This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/55446] New: array new with size zero vanishes from object code


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 <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]).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]