[backport from gcc-4.7/trunk ] gcc/cp/ 2011-03-16 Jason Merrill PR c++/47570 * semantics.c (cxx_eval_constant_expression) [COMPOUND_EXPR]: Don't use the generic binary expression handling. gcc/testsuite/ 2011-03-16 Jason Merrill * g++.dg/cpp0x/constexpr-47570.C: New. --- gcc-4.6-20110318/gcc/cp/semantics.c.~1~ 2011-03-08 06:28:13.000000000 +0100 +++ gcc-4.6-20110318/gcc/cp/semantics.c 2011-03-21 15:42:05.000000000 +0100 @@ -6896,7 +6896,13 @@ cxx_eval_constant_expression (const cons r = cxx_eval_constant_expression (call, op0, allow_non_constant, addr, non_constant_p); else - goto binary; + { + /* Check that the LHS is constant and then discard it. */ + cxx_eval_constant_expression (call, op0, allow_non_constant, + false, non_constant_p); + r = cxx_eval_constant_expression (call, op1, allow_non_constant, + addr, non_constant_p); + } } break; @@ -6938,7 +6944,6 @@ cxx_eval_constant_expression (const cons case UNEQ_EXPR: case RANGE_EXPR: case COMPLEX_EXPR: - binary: r = cxx_eval_binary_expression (call, t, allow_non_constant, addr, non_constant_p); break; --- gcc-4.6-20110318/gcc/testsuite/g++.dg/cpp0x/constexpr-47570.C.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.6-20110318/gcc/testsuite/g++.dg/cpp0x/constexpr-47570.C 2011-03-21 15:42:05.000000000 +0100 @@ -0,0 +1,25 @@ +// PR c++/47570 +// { dg-options -std=c++0x } + +unsigned int constexpr one() +{ return 1; } + +int constexpr one_B() +{ return 1; } + +int main() +{ + // FAIL TO COMPILE: + static bool constexpr SC_huh1 = ((unsigned int)one()) >= ((unsigned int)0); + static bool constexpr SC_huh2 = one() >= ((unsigned int)0); + static bool constexpr SC_huh3 = one() >= 0; + + // COMPILE OK: + static bool constexpr SC_huh4 = ((one() == 0) || (one() > 0)); + static bool constexpr SC_huh5 = one() == 0; + static bool constexpr SC_huh6 = one() > 0; + static bool constexpr SC_huh7 = one_B() >= 0; + static bool constexpr SC_huh8 = one() >= 1; + + return SC_huh3; +}