diff mbox

C++ PATCH for c++/47503 (C++0x ICE with trivial copy constructor and -fno-elide-constructors)

Message ID 4D60AD36.9010401@redhat.com
State New
Headers show

Commit Message

Jason Merrill Feb. 20, 2011, 5:57 a.m. UTC
With -fno-elide-constructors, the constexpr code was trying to set the 
type of a temporary of class type which was not represented by a 
CONSTRUCTOR.  The simplest solution to this is to just skip trivial 
copies at expand time and return the argument directly.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit b36ba34cf1f04e86dcb8b30c5cf90bb1900bcfee
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Feb 19 09:41:57 2011 -0500

    	PR c++/47503
    	* semantics.c (cxx_eval_call_expression): Shortcut trivial copy.
diff mbox

Patch

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index e102ba3..8944690 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -6019,6 +6019,10 @@  cxx_eval_call_expression (const constexpr_call *old_call, tree t,
       return t;
     }
 
+  /* Shortcut trivial copy constructor/op=.  */
+  if (call_expr_nargs (t) == 2 && trivial_fn_p (fun))
+    return convert_from_reference (get_nth_callarg (t, 1));
+
   /* If in direct recursive call, optimize definition search.  */
   if (old_call != NULL && old_call->fundef->decl == fun)
     new_call.fundef = old_call->fundef;
diff --git a/gcc/testsuite/g++.dg/cpp0x/regress/no-elide1.C b/gcc/testsuite/g++.dg/cpp0x/regress/no-elide1.C
new file mode 100644
index 0000000..50df950
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/regress/no-elide1.C
@@ -0,0 +1,14 @@ 
+// PR c++/47503
+// { dg-options "-std=c++0x -fno-elide-constructors" }
+
+struct A
+{
+  int i;
+  A ();
+};
+
+struct B
+{
+  A a;
+  B (A &aa) : a (aa) { }
+};