The following program compiles successfully and outputs nothing at all. In fact, the generated assembly has an empty "main". This happens even when compiling with -O0. #include <iostream> struct S { S() { } }; int main() { std::cout << new S[0] << " bla" << std::endl; } $ g++ new-opt.cc -Wall -Wextra $ ./a.out (no output) The issue goes away when removing the default constructor of "S". It seems gcc believes array-new with zero size is undefined behavior and thus removes the rest of the expression. I can't follow the "undefined behavior" part; array-new with zero size should yield a non-zero pointer (see 3.7.3.1p2 [basic.stc.dynamic.allocation] and 5.3.4p7 [expr.new]).
I observe the same thing with gcc 4.8.0 20121104 (experimental) on my mingw-x86_64 system. Odd.
Yes, this is confirmed.
build_new_1, called by build_new, returns error_mark_node. This happens because something goes very badly wrong in the cp_build_binary_op call around line 2712: essentially it computes 0 - 1!
And it's a regression.
And it's mine because I caused it with the fix for PR45385 :(
A compile-only test for this can be struct S { S(); }; void f(S *); void g() { S *s = new S[0]; f(s); } which causes a bogus warning: test.cc: In function 'void g()': test.cc:5:7: warning: 's' is used uninitialized in this function [-Wuninitialized]
Thanks. Relying on a warning seems a bit brittle, maybe a scan in the original dump would be good enough in terms of compile only testcases, but I sent to the mailing list a run time test.
Patch here: http://gcc.gnu.org/ml/gcc-patches/2012-11/msg01991.html
Ah, okay, an alternative compile-only testcase that does not rely on particular warnings would be struct S { S(); }; __typeof__(new S[0]) s; test.cc:2:23: error: invalid type in declaration before ';' token but if you've already got a good testcase, sure, go with that :)
Author: paolo Date: Sat Nov 24 23:45:45 2012 New Revision: 193785 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193785 Log: /cp 2012-11-24 Paolo Carlini <paolo.carlini@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-24 Paolo Carlini <paolo.carlini@oracle.com> PR c++/55446 * g++.dg/init/new41.C: New. Added: trunk/gcc/testsuite/g++.dg/init/new41.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/init.c trunk/gcc/testsuite/ChangeLog
Author: paolo Date: Sat Nov 24 23:55:22 2012 New Revision: 193786 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193786 Log: /cp 2012-11-24 Paolo Carlini <paolo.carlini@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-24 Paolo Carlini <paolo.carlini@oracle.com> PR c++/55446 * g++.dg/init/new41.C: New. Added: branches/gcc-4_7-branch/gcc/testsuite/g++.dg/init/new41.C Modified: branches/gcc-4_7-branch/gcc/cp/ChangeLog branches/gcc-4_7-branch/gcc/cp/init.c branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Fixed.
*** Bug 56146 has been marked as a duplicate of this bug. ***