Hi,
this is a wrong code regression unfortunately caused by my fix for
c++/45385.
The story went (*) that in order to fix the latter missing warning we
decided to remove the kludge added in c++/35602 to avoid a bogus warning
*and* we also decided to early return from build_vec_init when maxindex
is integer_all_onesp. Unfortunately the latter change caused the
regression at issue, because we want to exactly use integer_all_onesp
for perfectly valid things like:
new S[0]
At first, before I figured out the whole story, I thought we could solve
the problem by simply doing nothing in case of 0 but then we don't
reject a private default constructor for S. Using integer_zero_node or
any other normal value is also not Ok, because it means the default
constructor is actually called at least once. It seems we really want
the special value to go through build_vec_init as it used to up to 4.6.x.
Note that, currently at least, for the testcase added for c++/35602
build_vec_init is *not* used at all thus it can't possibly regress.
Tested x86_64-linux.
Thanks,
Paolo.
(*) http://gcc.gnu.org/ml/gcc-patches/2011-10/msg01946.html
/cp
2012-11-23 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/55446
* init.c (build_vec_init): Do not early return error_mark_mode
when integer_all_onesp (maxindex).
/testsuite
2012-11-23 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/55446
* g++.dg/init/new41.C: New.
Index: cp/init.c
===================================================================
--- cp/init.c (revision 193775)
+++ cp/init.c (working copy)
@@ -3283,8 +3283,7 @@ build_vec_init (tree base, tree maxindex, tree ini
if (TREE_CODE (atype) == ARRAY_TYPE && TYPE_DOMAIN (atype))
maxindex = array_type_nelts (atype);
- if (maxindex == NULL_TREE || maxindex == error_mark_node
- || integer_all_onesp (maxindex))
+ if (maxindex == NULL_TREE || maxindex == error_mark_node)
return error_mark_node;
if (explicit_value_init_p)
Index: testsuite/g++.dg/init/new41.C
===================================================================
--- testsuite/g++.dg/init/new41.C (revision 0)
+++ testsuite/g++.dg/init/new41.C (working copy)
@@ -0,0 +1,22 @@
+// PR c++/55446
+// { dg-do run }
+
+struct S
+{
+ S() { }
+};
+
+int n = 1;
+
+void* operator new[](__SIZE_TYPE__)
+{
+ n = -1;
+ return &n;
+}
+
+int main()
+{
+ new S[0];
+ if (n != -1)
+ __builtin_abort();
+}