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