[PATCH] Warn when NULL is returned from 'operator new' without 'throw()'
Artyom.Skrobov at arm.com
Thu Jan 9 12:03:04 PST 2014
C++03 section 184.108.40.206 item 3 specifies that "If an allocation function
declared with an empty exception-specification, throw(), fails to allocate
storage, it shall return a null pointer. Any other allocation function that
fails to allocate storage shall only indicate failure by throwing an
exception of class std::bad_alloc or a class derived from std::bad_alloc."
GCC does indeed issue a warning "'operator new' must not return NULL unless
it is declared 'throw()' (or -fcheck-new is in effect)" for blatant
violations of the aforementioned clause. Clang didn't support such a
warning, and implementing the support for -fcheck-new was dismissed in 2012
as "dubious" :
There is a related bugzilla ticket at
http://llvm.org/bugs/show_bug.cgi?id=16557 where Eric van Gyzen approaches
the issue at hand from a different direction: inserting runtime checks to
ensure the code is "safe" (i.e. not calling the constructor on a null
pointer) even when it's blatantly wrong as per above. We aren't sure about
the validity of that approach (catering for the incorrect code, in addition
to accepting it silently); so instead, we propose a patch that adds the
missing warning, matching GCC's.
OK to commit?
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 4156 bytes
Desc: not available
More information about the cfe-commits