diff mbox

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

Message ID 4D61F290.1040203@redhat.com
State New
Headers show

Commit Message

Jason Merrill Feb. 21, 2011, 5:05 a.m. UTC
But we still need to force constant evaluation of the result of 
convert_from_reference.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit a2889f0e13dd03b318cb2f60d2529d5adc57e07f
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Feb 20 21:23:58 2011 -0500

    	PR c++/47199
    	* semantics.c (cxx_eval_call_expression): Call
    	cxx_eval_constant_expression in trivial shortcut.
diff mbox

Patch

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 8944690..b7ed525 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -6021,7 +6021,11 @@  cxx_eval_call_expression (const constexpr_call *old_call, tree 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));
+    {
+      tree arg = convert_from_reference (get_nth_callarg (t, 1));
+      return cxx_eval_constant_expression (old_call, arg, allow_non_constant,
+					   addr, non_constant_p);
+    }
 
   /* If in direct recursive call, optimize definition search.  */
   if (old_call != NULL && old_call->fundef->decl == fun)
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor7.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor7.C
new file mode 100644
index 0000000..8338bf1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor7.C
@@ -0,0 +1,17 @@ 
+// PR c++/47199
+// { dg-options "-std=c++0x -fno-elide-constructors" }
+
+template < int > struct S
+{
+  constexpr S (int r):rr (r)
+  {
+  }
+  S (const S &) = default;
+  static constexpr S s ()
+  {
+    return -1;
+  }
+  int rr;
+};
+
+static const int d = S < 0 >::s ().rr;