This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/53839 (ICE with constexpr)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 13 Sep 2012 10:56:17 -0400
- Subject: C++ PATCH for c++/53839 (ICE with constexpr)
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.
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) };
+}