PR c++/47570
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 17 Mar 2011 02:36:04 +0000 (02:36 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 17 Mar 2011 02:36:04 +0000 (02:36 +0000)
* semantics.c (cxx_eval_constant_expression) [COMPOUND_EXPR]: Don't
use the generic binary expression handling.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@171083 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-47570.C [new file with mode: 0644]

index a2002b1..074c776 100644 (file)
@@ -1,3 +1,9 @@
+2011-03-16  Jason Merrill  <jason@redhat.com>
+
+       PR c++/47570
+       * semantics.c (cxx_eval_constant_expression) [COMPOUND_EXPR]: Don't
+       use the generic binary expression handling.
+
 2011-03-16  Diego Novillo  <dnovillo@google.com>
 
        * Make-lang.in (CXX_PARSER_H): New.
index ce24d46..a0c5ae3 100644 (file)
@@ -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;
index fd64f48..355e09d 100644 (file)
@@ -1,3 +1,7 @@
+2011-03-16  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/cpp0x/constexpr-47570.C: New.
+
 2011-03-16  Dodji Seketeli  <dodji@redhat.com>
 
        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 (file)
index 0000000..c60ba86
--- /dev/null
@@ -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;
+}