Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / gcc / testsuite / g++.dg / cpp0x / constexpr-neg2.C
1 // PR c++/54020
2 // { dg-do compile { target c++11 } }
3
4 // Preliminaries.
5 extern int nonconst_func(int);
6 constexpr int identity(int x) { return x; }
7 constexpr int zero() { return identity(0); }
8 constexpr int one() { return identity(1); }
9
10 // Correctly accepted.
11 constexpr int three = one() ? 3 : nonconst_func(0);
12
13 // Incorrectly accepted.  See [dcl.constexpr] #5:
14 //   For a constexpr function, if no function argument values exist
15 //   such that the function invocation sub-stitution would produce a
16 //   constant expression (5.19), the program is ill-formed; no diagnostic
17 //   required.
18 constexpr int bogus() { return zero () ? 3 : nonconst_func(0); } // { dg-error "nonconst_func" }
19
20 // Correctly rejected (not sure why).
21 constexpr int correct_error() { return nonconst_func(0); } // { dg-error "nonconst_func" }
22
23 // Correctly rejected.
24 constexpr int z = bogus();      // { dg-error "" }
25
26 // This is also correctly rejected.
27 constexpr int correct_failure() { return 0 ? 3 : nonconst_func(0); } // { dg-error "nonconst_func" }