<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Apr 2, 2014 at 5:47 PM, Robinson, Paul <span dir="ltr"><<a href="mailto:Paul_Robinson@playstation.sony.com" target="_blank">Paul_Robinson@playstation.sony.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">With -std=c++11, clang will complain about the expression in<br>
bar() but not foo().<br>
<br>
bool foo(int *p) { return (p != 0); }<br>
bool bar(int* p) { return (p != (1 - 1)); }<br>
<br>
With -std=c++03, clang accepts both.<br>
<br>
[expr.const]p3 has a Note that says an integral constant expression<br>
can be used as a null pointer constant.<br>
So, I think Clang should accept both even in C++11 mode.<br>
<br>
Bug, or my usual confusion about the standard? (I can see issuing<br>
a warning, because it would be hard to contrive a real-world case<br>
where somebody would actually want to do this; but if it conforms,<br>
Clang should not reject it.)</blockquote><div><br></div><div>This was changed by DR 903:</div><div><br></div><div> <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#903">http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#903</a></div>
<div><br></div><div>We implement this DR in C++11 onwards, since the C++98 rules are *really* broken when combined with C++11's generalized constant expressions. Without this change, ridiculous things like</div><div><br>
</div><div> struct S { int n; };</div><div> int *p = S().n;</div><div><br></div><div>... would compile, because S().n is an integral constant expression with value 0.</div></div></div></div>