<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div style="word-wrap:break-word"><div><div class="im"><div>We're going in circles. I think we agree that preferring nullptr to 0:</div>
</div><div><br></div><div>  (1) May prevent some mistakes arising from confusion between 0 being both an integer value and a null pointer , and</div><div>  (2) Is not in widespread use in C++ code today.</div><div><br></div>
<div>Your suggested warning about the use of 0 in a pointer context only makes sense if a particular code base follows this convention to start with, or the user wants to establish this convention. The former case is too rare now to consider (per (2)),</div>
</div></div></blockquote><div><br></div><div>Doesn't that make a perfect case for an off-by-default warning, then? Rather than users having to employ a separate tool (though, I admit, if a clang plugin is easy/lightweight enough I'm not at all averse to doing this sort of thing as a plugin. I'll certainly follow up on that) to ensure they don't make such mistakes.<br>
<br>It does seem a pity that even new C++ code would suffer the ills of old C++ code because the compiler is being overly cautious about existing code (that would be fairly easy to fix up in the case where someone is actually using C++0x features in their code already, and suppressed if they're just looking to ensure their code compiles as both C++98 and C++0x). Perpetrating more pointer mistakes even after features designed to help developers here have been standardized.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div style="word-wrap:break-word"><div><div> and the latter case is a style-checking issue that should not be a compiler warning.</div>
</div></div></blockquote><div><br></div><div>The point I'm making is that it's more than style - it has practical benefits that the compiler can understand the developers intent & provide diagnostics. How does the user know they're missing out on those useful diagnostics? Even if they know the diagnostics exist, it'll catch all their spurious NULL usage, but not the other way around (0 as null pointer) - that will be silently accepted without the use of an external tool.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div style="word-wrap:break-word"><div><div class="im"><div>Clang's purpose is not to migrate code from C++98 to C++0x. That's a separate tool one could build with Clang.</div>
</div></div></div></blockquote><div><br></div><div>Even once migrated, the user still has the ongoing risk of a 0 instead of nullptr & then clang's helpful diagnostics are silently suppressed. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div style="word-wrap:break-word"><div><div class="im">This is what one has to do to introduce a warning: implement it and see what the fallout is. With this warning, you're extremely likely to get an extremely low signal/noise ratio, especially because some coding standards actively encourage the use of 0 over NULL.</div>
</div></div></blockquote><div><br></div><div>Indeed - and I assume the parentheses warning had a low signal to noise ratio when it was first introduced too (that was more my point of giving the example). People had to transform all their existing code to conform to the pattern first (easy with clang, harder doing it manually with GCC) and from then on the diagnostic would help them.<br>
<br>Granted, parentheses probably had a higher s/n ratio than this warning would have. Assignments in conditionals are rare & the chance of misuse is higher, but still over a lot of code I'm sure there's a lot of legitimate usage that had to be fixed up when this warning was introduced, and all without the convenience of clang fixits. </div>
<div><br></div><div>Hmm: should the parentheses warning offer a fixit to add parens? It's already suggesting as much in text.</div><div> </div><div>- David</div></div>