From 3f7c74538130857eec303f1470673199ee7142d0 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 16 Mar 2011 22:36:04 -0400 Subject: [PATCH] re PR c++/47570 ([C++0x] "one() >= 0" isn't constexpr for unsigned int, yet == and > is.) PR c++/47570 * semantics.c (cxx_eval_constant_expression) [COMPOUND_EXPR]: Don't use the generic binary expression handling. From-SVN: r171083 --- gcc/cp/ChangeLog | 6 +++++ gcc/cp/semantics.c | 9 +++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/cpp0x/constexpr-47570.C | 25 ++++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-47570.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a2002b18494..074c776b08d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-03-16 Jason Merrill + + PR c++/47570 + * semantics.c (cxx_eval_constant_expression) [COMPOUND_EXPR]: Don't + use the generic binary expression handling. + 2011-03-16 Diego Novillo * Make-lang.in (CXX_PARSER_H): New. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index ce24d468bdd..a0c5ae327a9 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6915,7 +6915,13 @@ cxx_eval_constant_expression (const constexpr_call *call, tree t, 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; @@ -6957,7 +6963,6 @@ cxx_eval_constant_expression (const constexpr_call *call, tree t, 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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fd64f48e49b..355e09deac5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-03-16 Jason Merrill + + * g++.dg/cpp0x/constexpr-47570.C: New. + 2011-03-16 Dodji Seketeli PR debug/47510 diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-47570.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-47570.C new file mode 100644 index 00000000000..c60ba865862 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-47570.C @@ -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; +} -- 2.30.2