[cfe-dev] warn when ctor-initializer leaves uninitialized data?

Evan Wallace evan.exe at gmail.com
Mon Apr 9 10:47:35 PDT 2012


What would the interest be for a new warning that warns when POD member
variables are left out of the constructor initializer list and end up
uninitialized? That's bitten me many times and is especially hard on
beginners. Please correct me if I'm wrong but clang doesn't currently warn
about this. It looks like this warning is currently being implemented for
gcc (bug 2972). I don't have any experience with clang so I'm not sure if
this is the right place at all, but I took a stab at it last night on a
whim and it looks like adding the warning at the end of
BuildImplicitMemberInitializer() in SemaDeclCXX.cpp does the trick. If
there is interest, would this warning want to be added to the
-Wuninitialized group or would it want to be separate because it affects a
lot of existing code? What I have right now looks like this:

basic.cpp:1:22: warning: member 'y' is missing from constructor initializer
list [-Wuninitialized-member]
struct S { int x, y; S() : x() {} };

- Evan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120409/596822f8/attachment.html>

More information about the cfe-dev mailing list