PR c++/53356
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 30 May 2012 14:50:44 +0000 (14:50 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 30 May 2012 14:50:44 +0000 (14:50 +0000)
* tree.c (stabilize_init): Side effects make the init unstable.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@188019 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/new33.C [new file with mode: 0644]

index 5850ff6..f5ba6af 100644 (file)
@@ -1,3 +1,8 @@
+2012-05-30  Jason Merrill  <jason@redhat.com>
+
+       PR c++/53356
+       * tree.c (stabilize_init): Side effects make the init unstable.
+
 2012-05-28  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/53503
index 236180d..897d4d7 100644 (file)
@@ -3458,7 +3458,7 @@ stabilize_init (tree init, tree *initp)
 
   /* The initialization is being performed via a bitwise copy -- and
      the item copied may have side effects.  */
-  return TREE_SIDE_EFFECTS (init);
+  return !TREE_SIDE_EFFECTS (init);
 }
 
 /* Like "fold", but should be used whenever we might be processing the
index 49d88e7..ae6bdaf 100644 (file)
@@ -1,3 +1,8 @@
+2012-05-30  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/53356
+       * g++.dg/init/new33.C: New test.
+
 2012-05-30  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/53501
diff --git a/gcc/testsuite/g++.dg/init/new33.C b/gcc/testsuite/g++.dg/init/new33.C
new file mode 100644 (file)
index 0000000..18da79e
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/53356
+// { dg-do compile }
+
+struct A {};
+struct B { operator const A & () const; };
+struct C { operator const A & () const; C (); };
+struct D { operator const A & () const; D (); ~D (); };
+
+A *foo () { return new A (B ()); }
+A *bar () { return new A (C ()); }
+A *baz () { return new A (D ()); }