This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: operator new returns nonzero
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Mike Stump <mikestump at comcast dot net>
- Cc: Marc Glisse <marc dot glisse at inria dot fr>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 7 Sep 2013 19:34:35 -0500
- 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>
On Sat, Sep 7, 2013 at 2:46 PM, Mike Stump <mikestump@comcast.net> wrote:
>
> On Sep 7, 2013, at 12:37 PM, Gabriel Dos Reis <gdr@integrable-solutions.net> wrote:
>
>> On Sat, Sep 7, 2013 at 2:27 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
>>> On Sat, 7 Sep 2013, Mike Stump wrote:
>>>
>>>> On Sep 7, 2013, at 3:33 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
>>>>>
>>>>> this patch teaches the compiler that operator new, when it can throw,
>>>>> isn't allowed to return a null pointer.
>>>>
>>>>
>>>> You sure:
>>>>
>>>> @item -fcheck-new
>>>> @opindex fcheck-new
>>>> Check that the pointer returned by @code{operator new} is non-null
>>>> before attempting to modify the storage allocated. This check is
>>>> normally unnecessary because the C++ standard specifies that
>>>> @code{operator new} only returns @code{0} if it is declared
>>>> @samp{throw()}, in which case the compiler always checks the
>>>> return value even without this option. In all other cases, when
>>>> @code{operator new} has a non-empty exception specification, memory
>>>> exhaustion is signalled by throwing @code{std::bad_alloc}. See also
>>>> @samp{new (nothrow)}.
>>>>
>>>> ?
>>>
>>>
>>> Thanks, I didn't know that option. But it doesn't do the same.
>>
>> Indeed.
>
> Can this throw:
>
> void *operator new (long unsigned int s) {
> return 0;
> }
>
> ? Is this allowed to return 0?
If that is supposed to be a definition for the global function 'operator new',
then it fails the requirement of the C++ standards since 1998.
-- Gaby