[Bug c++/53330] New: new() operator can return NULL on a zero-length allocation
kilobyte at angband dot pl
gcc-bugzilla@gcc.gnu.org
Sat May 12 11:01:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53330
Bug #: 53330
Summary: new() operator can return NULL on a zero-length
allocation
Classification: Unclassified
Product: gcc
Version: 4.7.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: kilobyte@angband.pl
Created attachment 27386
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27386
test case
While in general C++ disallows zero-length arrays, they are explicitly allowed
by the new() operator (C++ 3.7.4.1.2), with a guarantee that such an allocation
will always return an unique non-null pointer.
This worked correctly in 4.6 and before (and clang, and MSVC, ...), 4.7.0
(Debian 4.7.0-8) and trunk@187013 return null if elements of the array have a
constructor and have sizeof() > 0 themselves. For simple types or structs, all
is ok.
Also, if there's a constructor (no regards for sizeof(element)) and the array
length is known at compile time, -Wuninitialized returns incorrect diagnostics
that the returned value is uninitialized.
More information about the Gcc-bugs
mailing list