Patchwork C++ PATCH for c++/55856 (ICE with tuple of reference)

login
register
mail settings
Submitter Jason Merrill
Date Jan. 3, 2013, 6:31 p.m.
Message ID <50E5CE80.9010205@redhat.com>
Download mbox | patch
Permalink /patch/209296/
State New
Headers show

Comments

Jason Merrill - Jan. 3, 2013, 6:31 p.m.
In the original testcase, the constexpr code was getting confused by a 
DECL_EXPR for a lifetime-extended temporary bound to the reference 
member of the tuple.

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

Patch

commit e9f73b2b5a67a425ae52755a6f9bebe16fc2398d
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Jan 3 13:16:14 2013 -0500

    	PR c++/55856
    	* semantics.c (build_data_member_initialization): Handle DECL_EXPR.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index f649399..9f8119f 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -5848,15 +5848,19 @@  build_data_member_initialization (tree t, vec<constructor_elt, va_gc> **vec)
       member = TREE_OPERAND (t, 0);
       init = unshare_expr (TREE_OPERAND (t, 1));
     }
-  else
+  else if (TREE_CODE (t) == CALL_EXPR)
     {
-      gcc_assert (TREE_CODE (t) == CALL_EXPR);
       member = CALL_EXPR_ARG (t, 0);
       /* We don't use build_cplus_new here because it complains about
 	 abstract bases.  Leaving the call unwrapped means that it has the
 	 wrong type, but cxx_eval_constant_expression doesn't care.  */
       init = unshare_expr (t);
     }
+  else if (TREE_CODE (t) == DECL_EXPR)
+    /* Declaring a temporary, don't add it to the CONSTRUCTOR.  */
+    return true;
+  else
+    gcc_unreachable ();
   if (TREE_CODE (member) == INDIRECT_REF)
     member = TREE_OPERAND (member, 0);
   if (TREE_CODE (member) == NOP_EXPR)
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor11.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor11.C
new file mode 100644
index 0000000..4b526ea
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor11.C
@@ -0,0 +1,16 @@ 
+// PR c++/55856
+// { dg-options -std=c++11 }
+
+struct A
+{
+  A(const char *);
+};
+
+template <class T>
+struct B
+{
+  T t;
+  template <class U> constexpr B(U&& u): t(u) { };
+};
+
+B<A&&> b("");