[cfe-commits] [Patch] Warn about self references in in-class initializers

Matt Beaumont-Gay matthewbg at google.com
Tue Sep 18 08:26:00 PDT 2012


On Tue, Sep 18, 2012 at 7:26 AM, Hans Wennborg <hans at chromium.org> wrote:
> Hi all,
>
> The attached patch makes Clang warn about self references in in-class
> initializers, for example:
>
> struct S {
>   int a = a + 42;
> };
>
> The patch basically just moves UninitializedFieldVisitor up a bit in
> the file, and adds a call to it from ActOnCXXInClassMemberInitializer.
>
> Please take a look.

LGTM; one nit:

+      // Also need to take into account that some fields may be initialized by
+      // in-class initializers, see C++0x [class.base.init]p9.

ITYM "C++11".

> Also, these warnings just say "field is
> unitialized when used here". Would anyone be opposed to changing it to
> "field 'a' is unitiailized when used here"?

Looking at other test cases in uninitialized.cpp, I think using the
field name in the diagnostic would be more consistent.

-Matt



More information about the cfe-commits mailing list