1// PR c++/54020
2// { dg-do compile { target c++11 } }
3
4// Preliminaries.
5extern int nonconst_func(int);
6constexpr int identity(int x) { return x; }
7constexpr int zero() { return identity(0); }
8constexpr int one() { return identity(1); }
9
10// Correctly accepted.
11constexpr 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.
18constexpr int bogus() { return zero () ? 3 : nonconst_func(0); } // { dg-error "nonconst_func" }
19
20// Correctly rejected (not sure why).
21constexpr int correct_error() { return nonconst_func(0); } // { dg-error "nonconst_func" }
22
23// Correctly rejected.
24constexpr int z = bogus();	// { dg-error "" }
25
26// This is also correctly rejected.
27constexpr int correct_failure() { return 0 ? 3 : nonconst_func(0); } // { dg-error "nonconst_func" }
28