Hi,
in this very old regression, which AFAICS dates back to when we started
using VECs, in templates we wrongly handle:
new char[size]
like
new char[size]()
Turns out the issue is simple: in build_new, when *init is null we
wrongly turn it into a pointer to an empty vector when we copy it into
orig_init, which is eventually used at the end of the function in the
build_raw_new_expr call. The comment at beginning of the latter explains
that this is exactly what we should not do ;)
The below passes bootstrap & testing on x86_64-linux. I'm not sure the
testcase can't be improved, I'm not very familiar with dg-final. Also,
in case we agree that the fix can be such simple, we could maybe
consider 4_7-branch too...
Thanks!
Paolo.
////////////////////////////
/cp
2012-10-26 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/54984
* init.c (build_new): Don't turn a null *init into a pointer to
empty vector orig_init.
/testsuite
2012-10-26 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/54984
* g++.dg/template/new11.C: New.
Index: cp/init.c
===================================================================
--- cp/init.c (revision 192814)
+++ 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)
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,18 @@
+// PR c++/54984
+// { dg-options "-fdump-tree-original" }
+
+template <class T>
+struct Foo
+{
+ Foo(__SIZE_TYPE__ size) : x(new char[size]) {}
+ char *x;
+};
+
+int main()
+{
+ __SIZE_TYPE__ size = 1000;
+ Foo<char> foo(size);
+}
+
+// { dg-final { scan-tree-dump-not "goto" "original" } }
+// { dg-final { cleanup-tree-dump "original" } }