http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
Bug #: 55446 Summary: array new with size zero vanishes from object code Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: jens.mau...@gmx.net Host: x86_64-unknown-linux-gnu Target: x86_64-unknown-linux-gnu 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]).