Patchwork C++ PATCH for c++/47003 (ICE with new and volatile)

login
register
mail settings
Submitter Jason Merrill
Date Dec. 22, 2010, 7:13 p.m.
Message ID <4D124DE3.1000409@redhat.com>
Download mbox | patch
Permalink /patch/76440/
State New
Headers show

Comments

Jason Merrill - Dec. 22, 2010, 7:13 p.m.
My earlier change to stabilize_expr was just wrong; if a type doesn't 
need to be created by a constructor, we want to save its value, not the 
glvalue that designates its address.  This patch restores the previous 
use of TYPE_NEEDS_CONSTRUCTING, while leaving alone the actual xvalue 
changes.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit 2b226072923eef3ee84d04d3a60f4cdb7657e3bd
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Dec 20 14:07:49 2010 -0500

    	PR c++/47003
    	* tree.c (stabilize_expr): Really stabilize scalar glvalues.

Patch

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 1a77dc1..ecb764a 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -3058,9 +3058,7 @@  stabilize_expr (tree exp, tree* initp)
 
   if (!TREE_SIDE_EFFECTS (exp))
     init_expr = NULL_TREE;
-  /* There are no expressions with REFERENCE_TYPE, but there can be call
-     arguments with such a type; just treat it as a pointer.  */
-  else if (TREE_CODE (TREE_TYPE (exp)) == REFERENCE_TYPE
+  else if (!TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (exp))
 	   || !lvalue_or_rvalue_with_address_p (exp))
     {
       init_expr = get_target_expr (exp);
diff --git a/gcc/testsuite/g++.dg/init/volatile2.C b/gcc/testsuite/g++.dg/init/volatile2.C
new file mode 100644
index 0000000..036d5f1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/volatile2.C
@@ -0,0 +1,13 @@ 
+// PR c++/47003
+
+struct A
+{
+  A(int);
+};
+
+volatile int i;
+
+int main()
+{
+  A *q = new A (i);
+}