OSDN Git Service

PR c++/54777
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 3 Oct 2012 14:27:30 +0000 (14:27 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 3 Oct 2012 14:27:30 +0000 (14:27 +0000)
* semantics.c (cxx_eval_constant_expression) <case COMPOUND_EXPR>: If
not ignoring the second operand, pass the original second operand
and not one with stripped nops to cxx_eval_constant_expression.

* g++.dg/cpp0x/constexpr-ref4.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@192037 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 1c836d3..afe99a2 100644 (file)
@@ -1,3 +1,10 @@
+2012-10-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/54777
+       * semantics.c (cxx_eval_constant_expression) <case COMPOUND_EXPR>: If
+       not ignoring the second operand, pass the original second operand
+       and not one with stripped nops to cxx_eval_constant_expression.
+
 2012-09-20  Release Manager
 
        * GCC 4.7.2 released.
index a64c5b7..7371b44 100644 (file)
@@ -7682,6 +7682,7 @@ cxx_eval_constant_expression (const constexpr_call *call, tree t,
            /* Check that the LHS is constant and then discard it.  */
            cxx_eval_constant_expression (call, op0, allow_non_constant,
                                          false, non_constant_p);
+           op1 = TREE_OPERAND (t, 1);
            r = cxx_eval_constant_expression (call, op1, allow_non_constant,
                                              addr, non_constant_p);
          }
index 48f6ead..c700ca6 100644 (file)
@@ -1,3 +1,8 @@
+2012-10-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/54777
+       * g++.dg/cpp0x/constexpr-ref4.C: New test.
+
 2012-09-30  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
 
        PR target/54083
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ref4.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ref4.C
new file mode 100644 (file)
index 0000000..6ae355a
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/54777
+// { dg-options -std=c++0x }
+
+struct S
+{
+  int s[1];
+  constexpr const int &foo (unsigned i) { return (i < 1 ? 0 : throw 1), s[i]; }
+  constexpr const int &bar (unsigned i) { return i < 1 ? s[i] : (throw 0, s[i]); }
+};
+
+int
+main ()
+{
+  constexpr S a {};
+  constexpr int i = a.foo (0);
+  constexpr int j = a.bar (0);
+  static_assert (i == j, "Ouch");
+}