Patchwork [C++] PR 54984

login
register
mail settings
Submitter Paolo Carlini
Date Oct. 26, 2012, 1:54 p.m.
Message ID <508A9608.2060005@oracle.com>
Download mbox | patch
Permalink /patch/194482/
State New
Headers show

Comments

Paolo Carlini - Oct. 26, 2012, 1:54 p.m.
Hi,

On 10/26/2012 02:44 PM, Jason Merrill wrote:
> On 10/25/2012 09:15 PM, Paolo Carlini wrote:
>> I'm not sure the testcase can't be improved, I'm not very familiar with
>> dg-final.
>
> You could do an execution test using a user-defined operator new which 
> initializes the memory to something other than 0.  OK with that change.
>
>> Also, in case we agree that the fix can be such simple, we
>> could maybe consider 4_7-branch too...
>
> Sure.
Thanks. The below is what I'm going to apply mainline and 4_7-branch.

Paolo.

////////////////////

Patch

Index: testsuite/g++.dg/template/new11.C
===================================================================
--- testsuite/g++.dg/template/new11.C	(revision 0)
+++ testsuite/g++.dg/template/new11.C	(working copy)
@@ -0,0 +1,28 @@ 
+// PR c++/54984
+// { dg-do run }
+
+int n = 1;
+
+void* operator new(__SIZE_TYPE__)
+{
+  n = -1;
+  return &n;
+}
+
+template <class T>
+struct Foo
+{
+  Foo()
+  : x(new int)
+  {
+    if (*x != -1)
+      __builtin_abort();
+  }
+
+  int* x;
+};
+
+int main()
+{
+  Foo<float> foo;
+}
Index: cp/init.c
===================================================================
--- cp/init.c	(revision 192839)
+++ cp/init.c	(working copy)
@@ -2911,7 +2911,8 @@  build_new (VEC(tree,gc) **placement, tree type, tr
 
       orig_placement = make_tree_vector_copy (*placement);
       orig_nelts = nelts;
-      orig_init = make_tree_vector_copy (*init);
+      if (*init)
+	orig_init = make_tree_vector_copy (*init);
 
       make_args_non_dependent (*placement);
       if (nelts)