From patchwork Thu Jan 3 18:31:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: C++ PATCH for c++/55856 (ICE with tuple of reference) Date: Thu, 03 Jan 2013 08:31:28 -0000 From: Jason Merrill X-Patchwork-Id: 209296 Message-Id: <50E5CE80.9010205@redhat.com> To: gcc-patches List 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. commit e9f73b2b5a67a425ae52755a6f9bebe16fc2398d Author: Jason Merrill 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 **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 +struct B +{ + T t; + template constexpr B(U&& u): t(u) { }; +}; + +B b("");