]> gcc.gnu.org Git - gcc.git/commitdiff
re PR c++/57901 (Cannot call-by-value such that class has non-trivial (constexpr...
authorJason Merrill <jason@redhat.com>
Tue, 30 Jul 2013 13:28:31 +0000 (09:28 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 30 Jul 2013 13:28:31 +0000 (09:28 -0400)
PR c++/57901
* semantics.c (build_data_member_initialization, constexpr_fn_retval):
Use break_out_target_exprs instead of unshare_expr.

From-SVN: r201338

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp0x/constexpr-value4.C [new file with mode: 0644]

index 1bedc84621582336da388f98c9bd636630507a90..72acda1cba8602832456e4b37f6a7bfb43711918 100644 (file)
@@ -1,3 +1,9 @@
+2013-07-29  Jason Merrill  <jason@redhat.com>
+
+       PR c++/57901
+       * semantics.c (build_data_member_initialization, constexpr_fn_retval):
+       Use break_out_target_exprs instead of unshare_expr.
+
 2013-07-29  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/57948
index f68d3863ab1ef2e0f627eb60f05f6210ac7933b8..acdd1788f6ee4c82b398f1299befb05ad4632961 100644 (file)
@@ -6016,7 +6016,7 @@ build_data_member_initialization (tree t, vec<constructor_elt, va_gc> **vec)
       || TREE_CODE (t) == MODIFY_EXPR)
     {
       member = TREE_OPERAND (t, 0);
-      init = unshare_expr (TREE_OPERAND (t, 1));
+      init = break_out_target_exprs (TREE_OPERAND (t, 1));
     }
   else if (TREE_CODE (t) == CALL_EXPR)
     {
@@ -6024,7 +6024,7 @@ build_data_member_initialization (tree t, vec<constructor_elt, va_gc> **vec)
       /* 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);
+      init = break_out_target_exprs (t);
     }
   else if (TREE_CODE (t) == DECL_EXPR)
     /* Declaring a temporary, don't add it to the CONSTRUCTOR.  */
@@ -6261,7 +6261,7 @@ constexpr_fn_retval (tree body)
       }
 
     case RETURN_EXPR:
-      return unshare_expr (TREE_OPERAND (body, 0));
+      return break_out_target_exprs (TREE_OPERAND (body, 0));
 
     case DECL_EXPR:
       if (TREE_CODE (DECL_EXPR_DECL (body)) == USING_DECL)
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-value4.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-value4.C
new file mode 100644 (file)
index 0000000..1fc3738
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/57901
+// { dg-require-effective-target c++11 }
+
+struct Z {
+    Z()         = default;
+    Z(Z const&) = default;
+    constexpr Z(Z&&) {} /* non-trivial (constexpr) move ctor */
+};
+
+template<typename T>
+constexpr int fn0(T v) { return 0; }
+template<typename T>
+constexpr int fn (T v) { return fn0(v); }
+
+constexpr auto t0 = fn0(Z()); // OK!
+constexpr auto t  = fn (Z()); // error! (GCC 4.8.1)
This page took 0.09115 seconds and 5 git commands to generate.