Patchwork C++ PATCH for c++/53839 (ICE with constexpr)

login
register
mail settings
Submitter Jason Merrill
Date Sept. 13, 2012, 2:56 p.m.
Message ID <5051F411.8060209@redhat.com>
Download mbox | patch
Permalink /patch/183640/
State New
Headers show

Comments

Jason Merrill - Sept. 13, 2012, 2:56 p.m.
We weren't requiring the result of an INDIRECT_REF to be a constant 
because we could end up taking its address again later, so in this case 
we ended up trying to handle a non-constant expression as a constant and 
failing.  But since we have the "addr" parameter we know whether or not 
we will end up taking the address again, and we can require a constant 
if not.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.7.

Patch

commit 4156683505c976d284fe38eb3a5ca40812ae5d66
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Sep 11 06:15:25 2012 -0400

    	PR c++/53839
    	* semantics.c (cxx_eval_indirect_ref): If we aren't looking for an
    	address, make sure the value is constant.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index a6cdfb5..d19ff1c 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -7474,7 +7474,11 @@  cxx_eval_indirect_ref (const constexpr_call *call, tree t,
     }
 
   if (r == NULL_TREE)
-    return t;
+    {
+      if (!addr)
+	VERIFY_CONSTANT (t);
+      return t;
+    }
   return r;
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-temp1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-temp1.C
new file mode 100644
index 0000000..d065436
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-temp1.C
@@ -0,0 +1,9 @@ 
+// { dg-do compile { target c++11 } }
+
+struct A { int i; };
+constexpr A f2 (const A& a) { return a; }
+constexpr int f1 (const A &a) { return f2(a).i; }
+A g(const A &a)
+{
+  return { f1(a) };
+}