This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/53356 (C++11 ICE with new)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 30 May 2012 10:44:55 -0400
- Subject: C++ PATCH for c++/53356 (C++11 ICE with new)
The code in build_new_1 already knows how to handle an initializer that
it was unable to stabilize, but the logic was backwards in a critical
place. I'm surprised this typo hasn't been hit before since it was
introduced in 2006...
Tested x86_64-pc-linux-gnu, applying to trunk and 4.7.
commit b2e577b5a53a4c49bb3eea682e2c1dee86c27316
Author: Jason Merrill <jason@redhat.com>
Date: Wed May 30 09:29:37 2012 -0400
PR c++/53356
* tree.c (stabilize_init): Side effects make the init unstable.
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 236180d..897d4d7 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -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
diff --git a/gcc/testsuite/g++.dg/init/new33.C b/gcc/testsuite/g++.dg/init/new33.C
new file mode 100644
index 0000000..18da79e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/new33.C
@@ -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 ()); }