2007-12-05 Jakub Jelinek PR c++/34336 * init.c (build_new_1): Don't call stabilize_call or stabilize_init if processing_template_decl. * g++.dg/template/new8.C: New test. --- gcc/cp/init.c.jj 2007-11-23 20:33:49.000000000 +0100 +++ gcc/cp/init.c 2007-12-05 20:14:59.000000000 +0100 @@ -1889,7 +1889,7 @@ build_new_1 (tree placement, tree type, /* Preevaluate the placement args so that we don't reevaluate them for a placement delete. */ - if (placement_allocation_fn_p) + if (placement_allocation_fn_p && !processing_template_decl) { tree inits; stabilize_call (alloc_call, &inits); @@ -2000,7 +2000,10 @@ build_new_1 (tree placement, tree type, complete_ctor_identifier, init, elt_type, LOOKUP_NORMAL); - stable = stabilize_init (init_expr, &init_preeval_expr); + if (processing_template_decl) + stable = true; + else + stable = stabilize_init (init_expr, &init_preeval_expr); } else { @@ -2015,7 +2018,10 @@ build_new_1 (tree placement, tree type, || TREE_TYPE (init) != NULL_TREE); init_expr = build_modify_expr (init_expr, INIT_EXPR, init); - stable = stabilize_init (init_expr, &init_preeval_expr); + if (processing_template_decl) + stable = true; + else + stable = stabilize_init (init_expr, &init_preeval_expr); } } --- gcc/testsuite/g++.dg/template/new8.C.jj 2007-12-05 18:02:04.000000000 +0100 +++ gcc/testsuite/g++.dg/template/new8.C 2007-12-05 18:01:30.000000000 +0100 @@ -0,0 +1,29 @@ +// PR c++/34336 +// { dg-do compile } + +struct A; + +template +struct S +{ + T *m; + T &operator* () { return *m; } +}; + +struct B +{ + B (const A &); +}; + +template +struct C +{ + C (); + S c; +}; + +template +C::C () +{ + B *b = new B (*c); +}