From patchwork Fri Oct 26 13:54:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [C++] PR 54984 Date: Fri, 26 Oct 2012 03:54:16 -0000 From: Paolo Carlini X-Patchwork-Id: 194482 Message-Id: <508A9608.2060005@oracle.com> To: Jason Merrill Cc: "gcc-patches@gcc.gnu.org" 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. //////////////////// 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 +struct Foo +{ + Foo() + : x(new int) + { + if (*x != -1) + __builtin_abort(); + } + + int* x; +}; + +int main() +{ + Foo 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)