[cfe-commits] Null init suggestion

Douglas Gregor dgregor at apple.com
Fri Aug 26 17:20:11 PDT 2011


On Aug 26, 2011, at 2:53 PM, David Blaikie wrote:

> Surprisingly, unrelated to this whole discussion about nullptr usage, etc, I came across this fixit note that could be improved for C++0x:
> 
> foo.cpp:6:7: warning: variable 'i' is uninitialized when used here [-Wuninitialized]
>   foo(i);
>       ^
> foo.cpp:5:3: note: variable 'i' is declared here
>   int* i;
>   ^
> foo.cpp:5:9: note: add initialization to silence this warning
>   int* i;
>         ^
>          = NULL
> 
> (no color this time - the demo page doesn't do warning flags yet, so I had to copy/paste this from a terminal instead)
> 
> This warning currently suggests NULL if it's defined* otherwise it suggests 0. This patch enhances this to prefer nullptr over either of these if compiling as C++0x, otherwise to fall back to NULL then 0.

Committed as r138687, thanks!

> Side note: Do we really need that first note if we're providing the second note? I realize in some cases the first note is all we'll get, because there's no initialization we can guess to provide. But in the cases where there is an init suggestion, could we just provide that instead of the "variable '%s' is declared here"?

Good point. It seems that we don't need to provide the first note if we know we're providing the second. Looping in Ted to get his opinion.

	- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110826/1e30239a/attachment.html>


More information about the cfe-commits mailing list