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

Hans Wennborg hans at chromium.org
Tue Sep 18 09:01:35 PDT 2012


Thanks for the review!

On Tue, Sep 18, 2012 at 4:26 PM, Matt Beaumont-Gay <matthewbg at google.com> wrote:
> 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".

Fixed.

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

Cool. I'll do this in a follow-up patch.

Landed in r164131.

Thanks,
Hans



More information about the cfe-commits mailing list