[cfe-dev] -fno-exceptions and operator new
Robinson, Paul
Paul_Robinson at playstation.sony.com
Thu Aug 1 12:19:14 PDT 2013
Suppose a class Foo has a user-supplied operator new, that can return null.
The standard permits this behavior if operator new is marked as 'noexcept'
or 'throw()'.
If operator new cannot throw, then when we 'new Foo' and the operator
returns null, Clang generates code to detect that case and skips calling
the object constructor.
Now suppose operator new is NOT marked 'noexcept' but instead we compile
the program with -fno-exceptions; it turns out that Clang treats this
operator new as if it could throw--that is, it will not detect the null
return value and calls the constructor with a null 'this' pointer (with
predictable consequences). Shouldn't this case be equivalent to marking
our operator new with 'noexcept', and check for the null return value?
Thanks,
--paulr
More information about the cfe-dev
mailing list