This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: operator new returns nonzero
- From: Marc Glisse <marc dot glisse at inria dot fr>
- To: Mike Stump <mikestump at comcast dot net>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 7 Sep 2013 23:08:33 +0200 (CEST)
- Subject: Re: operator new returns nonzero
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot DEB dot 2 dot 02 dot 1309071206340 dot 19326 at stedding dot saclay dot inria dot fr> <7209CCD2-9BA5-4CD2-8A2B-9DEF2D2C88D2 at comcast dot net> <alpine dot DEB dot 2 dot 10 dot 1309072117090 dot 3585 at laptop-mg dot saclay dot inria dot fr> <CAAiZkiCsLHAmw3cgDFX3O=ibnSJ-Eo_fmtMFx+sCJD=sBjS5HA at mail dot gmail dot com> <8314FBDA-0F5E-4772-A7D6-49319390170B at comcast dot net> <alpine dot DEB dot 2 dot 10 dot 1309072201190 dot 3585 at laptop-mg dot saclay dot inria dot fr>
On Sat, 7 Sep 2013, Marc Glisse wrote:
On Sat, 7 Sep 2013, Mike Stump wrote:
Can this throw:
void *operator new (long unsigned int s) {
return 0;
}
? Is this allowed to return 0?
I think using this function is illegal. It isn't marked noexcept, so it isn't
allowed to return 0.
And if I compile your code with gcc, I get nice warnings (though I get
them twice and the column number is not so good):
m.cc: In function 'void* operator new(long unsigned int)':
m.cc:2:12: warning: 'operator new' must not return NULL unless it is
declared 'throw()' (or -fcheck-new is in effect) [enabled by default]
return 0;
^
m.cc: At global scope:
m.cc:1:7: warning: unused parameter 's' [-Wunused-parameter]
void *operator new (long unsigned int s) {
^
--
Marc Glisse