diff mbox

C++ PATCH for c++/47041 (crash with c++0x and -fno-elide-constructors)

Message ID 4D3A08EE.9090603@redhat.com
State New
Headers show

Commit Message

Jason Merrill Jan. 21, 2011, 10:30 p.m. UTC
It puzzles me that people actually use -fno-elide-constructors, but as 
long as it's in the compiler it ought to work, and it's probably 
possible to run into this bug without that flag: a trivial copy ctor/op= 
is implemented with a single big assignment rather than memberwise copy, 
so we need to handle that case.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit ce3d514493c3e54adc5ce2889e6af75692289793
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jan 21 16:10:18 2011 -0500

    	PR c++/47041
    	* semantics.c (build_constexpr_constructor_member_initializers):
    	Handle trivial copy.
diff mbox

Patch

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index fa35d4a..fae9948 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -5605,7 +5605,20 @@  build_constexpr_constructor_member_initializers (tree type, tree body)
     body = STATEMENT_LIST_HEAD (body)->stmt;
   body = BIND_EXPR_BODY (body);
   if (TREE_CODE (body) == CLEANUP_POINT_EXPR)
-    ok = build_data_member_initialization (body, &vec);
+    {
+      body = TREE_OPERAND (body, 0);
+      if (TREE_CODE (body) == EXPR_STMT)
+	body = TREE_OPERAND (body, 0);
+      if (TREE_CODE (body) == INIT_EXPR
+	  && (same_type_ignoring_top_level_qualifiers_p
+	      (TREE_TYPE (TREE_OPERAND (body, 0)),
+	       current_class_type)))
+	{
+	  /* Trivial copy.  */
+	  return TREE_OPERAND (body, 1);
+	}
+      ok = build_data_member_initialization (body, &vec);
+    }
   else if (TREE_CODE (body) == STATEMENT_LIST)
     {
       tree_stmt_iterator i;
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor6.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor6.C
new file mode 100644
index 0000000..4f86f73
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ctor6.C
@@ -0,0 +1,9 @@ 
+// PR c++/47041
+// { dg-options "-std=c++0x -fno-elide-constructors" }
+
+struct S
+{
+  int i;
+};
+
+S s = S ();