public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53330] New: new() operator can return NULL on a zero-length allocation
@ 2012-05-12 11:01 kilobyte at angband dot pl
  2012-05-12 11:03 ` [Bug c++/53330] " kilobyte at angband dot pl
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: kilobyte at angband dot pl @ 2012-05-12 11:01 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-08-12 22:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-12 11:01 [Bug c++/53330] New: new() operator can return NULL on a zero-length allocation kilobyte at angband dot pl
2012-05-12 11:03 ` [Bug c++/53330] " kilobyte at angband dot pl
2013-03-29 13:13 ` kilobyte at angband dot pl
2013-03-29 13:21 ` kilobyte at angband dot pl
2015-08-12 22:38 ` paolo at gcc dot gnu.org
2015-08-12 22:39 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).