<div dir="ltr"><div>Thanks!</div><div><br></div><div>I added some more test cases for dependent exception specifications, found they failed, and fixed up the implementation to handle them appropriately. I delayed the check until after we've converted the return expression to the return type, to avoid issuing the warning if the expression is ill-formed (as happened for the 'return 1 - 1;' testcase in C++11). I also merged together the C++98 and C++11 test files.</div>
<div><br></div><div>With those changes, committed as r199452.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jan 15, 2014 at 3:00 AM, Artyom Skrobov <span dir="ltr"><<a href="mailto:Artyom.Skrobov@arm.com" target="_blank">Artyom.Skrobov@arm.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im HOEnZb">Hello Richard,<br>
<br>
Would you please be able to review my updated patch?<br>
(attaching it again, just in case)<br>
<br>
<br>
<br>
From: <a href="mailto:metafoo@gmail.com">metafoo@gmail.com</a> [mailto:<a href="mailto:metafoo@gmail.com">metafoo@gmail.com</a>] On Behalf Of Richard<br>
Smith<br>
Sent: 10 January 2014 23:25<br>
To: Artyom Skrobov<br>
Cc: cfe commits<br>
Subject: Re: [PATCH] Warn when NULL is returned from 'operator new' without<br>
'throw()'<br>
<br>
</div><div class="HOEnZb"><div class="h5">On Fri, Jan 10, 2014 at 5:07 AM, Artyom Skrobov <<a href="mailto:Artyom.Skrobov@arm.com">Artyom.Skrobov@arm.com</a>><br>
wrote:<br>
Thank you for your suggestions Richard!<br>
One point though:<br>
> Please use RetValExp->isNullPointerConstant instead.<br>
> Please also add testcases for operator new returning nullptr, and<br>
returning expressions such as 1 - 1, and for operator new marked as<br>
'noexcept'.<br>
I want to note that expressions such as 1-1 are invalid as return values<br>
from operator new, and produce "error: cannot initialize return object of<br>
type 'void *' with an rvalue of type 'int'"<br>
<br>
Expressions such as 1 - 1 are valid null pointer constants in C++98 but not<br>
in C++11.<br>
 <br>
At the same time, expressions such as (void*)(1-1) are not recognized either<br>
by isNullPointerConstant or by EvaluateAsInt as integer zeroes, namely<br>
because they are not integers.<br>
<br>
In C++11, (void*)(1 - 1) is a reinterpret_cast of 0 to void*, and isn't<br>
(necessarily) a null pointer. In C++98, it's a static_cast, and is a null<br>
pointer.<br>
 <br>
For a reference, GCC doesn't warn on<br>
<br>
   void *operator new(size_t n) {<br>
     return (void*)(1-1);<br>
   }<br>
<br>
which isn't too bad; but neither does it warn on<br>
<br>
   void *operator new(size_t n) {<br>
     void* blah = 0;<br>
     return blah;<br>
   }<br>
<br>
OK, I would not expect a warning here.<br>
 <br>
nor even on<br>
<br>
   void *operator new(size_t n) {<br>
     return (void*)0;<br>
   }<br>
<br>
I *would* expect a warning here.<br>
 <br>
which seems quite valuable to be able to detect.<br>
<br>
isNullPointerConstant doesn't recognize the two latter cases as null pointer<br>
constants, either.<br>
<br>
Sorry for sending you in the wrong direction!<br>
 <br>
Do you think Clang should be able to detect such null-pointer-expressions?<br>
If so, could you advise how it could be implemented, seeing that<br>
isNullPointerConstant and EvaluateAsInt prove ineffective?<br>
<br>
It looks like the best way to achieve this is to use<br>
Expr::EvaluateAsBooleanCondition on the (converted) return expression. That<br>
matches what we do for __attribute__((nonnull)).</div></div><br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div>