From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11125 invoked by alias); 23 Nov 2012 10:49:46 -0000 Received: (qmail 10909 invoked by uid 48); 23 Nov 2012 10:48:47 -0000 From: "jens.maurer at gmx dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/55446] New: array new with size zero vanishes from object code Date: Fri, 23 Nov 2012 10:49:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: major X-Bugzilla-Who: jens.maurer at gmx dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-11/txt/msg02179.txt.bz2 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: unassigned@gcc.gnu.org ReportedBy: jens.maurer@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 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]).