[cfe-commits] Null init suggestion

David Blaikie dblaikie at gmail.com
Fri Aug 26 14:53:25 PDT 2011

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
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.

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"?

- David

* neat stuff, btw - though I wonder how smart that engine is - obviously
it's not caring about whether it finds the real stdlib NULL or some
user-defined, unrelated NULL (but that's probably ok) - but it does make me
wonder how it's keeping track of/representing the current state of the
preprocessor so that if I define NULL between one line & the next it somehow
gets it right. Oh, I guess it doesn't - if I don't define NULL until after
that line it still suggests that I use NULL. Eh, near enough I think.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110826/81c86736/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: null_init_suggestion.patch
Type: application/octet-stream
Size: 716 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110826/81c86736/attachment.obj>

More information about the cfe-commits mailing list