[cfe-dev] Implementing missing-braces warning

Tanya Lattner lattner at apple.com
Fri Jan 29 15:58:13 CST 2010


> 
> I think GCC has the warning mostly right. Pointing out which subobject we're in ('a[0]') is really helpful, although it should be folded into the diagnostic itself. Clang should also highlight (with a source range) all of the initializers that are conceptually initializing that subobject, e.g.,
> 
> warning: missing braces around initialization of subobject 'a[0]'
> int a[2][2] = { 0, 1, 2, 3 };
>                ^~~~
>                {   }
> 
> I'm not thrilled with the use of the word "missing", which seems to imply an actual error. I somewhat prefer:
> 
> 	warning: suggest braces around initialization of subobject 'a[0]'
> 

Ok. So, how do I get "a[0]" from the InitListExpr?

>> Should code modification hints be given?
> 
> Yes! The hints should definitely insert the '{' and '}' in the right place.
> 

Ok, did this.

>> Is one warning output or one for each set of braces needed?
> 
> One for each set of braces, IMO.

Ok, did this too.

> 
>> As for implementation details, in SemaInit::CheckSubElementType we assume brace elision. I assume that this is where I should output my warning, but when i do it there, I get one for each set (so 2 warnings). Any advice here? 
> 
> 
> Did you try CheckImplicitInitList? IIRC, that's where we're implicitly stepping into a subobject when initializing a list.
> 

Awesome. This works great!

Thanks Doug!

-Tanya




More information about the cfe-dev mailing list