r199452 - Issue a warning if a throwing operator new or operator new[] returns a null
Richard Smith
richard at metafoo.co.uk
Wed Feb 12 08:35:42 PST 2014
On Mon, Feb 10, 2014 at 1:02 PM, Joerg Sonnenberger <joerg at britannica.bec.de
> wrote:
> On Fri, Jan 17, 2014 at 02:09:33AM -0000, Richard Smith wrote:
> > Author: rsmith
> > Date: Thu Jan 16 20:09:33 2014
> > New Revision: 199452
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=199452&view=rev
> > Log:
> > Issue a warning if a throwing operator new or operator new[] returns a
> null
> > pointer, since this invokes undefined behavior. Based on a patch by
> Artyom
> > Skrobov! Handling of dependent exception specifications and some
> additional
> > testcases by me.
>
> OpenJDK contains code like
>
> void *foo::operator new(size_t, bar &, int, TRAPS) {
> if (error_condition)
> return 0;
> return some_value;
> }
>
> Should this warning really apply here?
>
Yes, this is exactly the code that we wanted this warning to catch. If
'error_condition' is true, this code has undefined behavior.
Another issue is that it doesn't check whether the return statement is
> actually reachable, e.g. a __builtin_unreachable() just before it does
> not silence the warning. I think it should.
Sure, if you want to go ahead and change the Diag to DiagRuntimeBehavior in
CheckReturnValExpr, that seems fine to me.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140212/4711dfbd/attachment.html>
More information about the cfe-commits
mailing list