[C++ PATCH] Fix ICE with COMPOUND_EXPR in constexpr (PR c++/54777)

Jakub Jelinek jakub@redhat.com
Tue Oct 2 21:29:00 GMT 2012


Hi!

We ICE on the following testcase, because cxx_eval_constant_expression
on COMPOUND_EXPR uses STRIP_NOPS (op1) - needed for the check whether it
is an artificial COMPOUND_EXPR.  Unfortunately that means it uses op1
without NOP_EXPRs even if it is a user comma expression.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk/4.7?

2012-10-02  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.

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

--- gcc/cp/semantics.c.jj	2012-10-01 18:12:01.000000000 +0200
+++ gcc/cp/semantics.c	2012-10-02 12:05:47.229669955 +0200
@@ -7772,6 +7772,7 @@ cxx_eval_constant_expression (const cons
 	    /* 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);
 	  }
--- gcc/testsuite/g++.dg/cpp0x/constexpr-ref4.C.jj	2012-10-02 12:11:12.886978774 +0200
+++ gcc/testsuite/g++.dg/cpp0x/constexpr-ref4.C	2012-10-02 12:12:13.085636591 +0200
@@ -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");
+}

	Jakub



More information about the Gcc-patches mailing list