[cfe-commits] [PATCH] missing braces warning

Douglas Gregor dgregor at apple.com
Sat Mar 6 19:55:21 PST 2010


Looks good, thanks!

On Mar 6, 2010, at 6:56 PM, Tanya Lattner wrote:

> Doug,
> 
> Attached is the updated patch. If you have time to review before 2.7 branches, I can get it in.
> 
> <missingBraces.patch>
> 
> -Tanya
> 
> On Mar 1, 2010, at 8:23 AM, Douglas Gregor wrote:
> 
>> 
>> On Feb 18, 2010, at 10:55 AM, Tanya Lattner wrote:
>> 
>>> Attached is a patch that implements missing braces warning and updates some test cases. Let me know what you think.
>> 
>> 
>> Sorry for the delay...
>> 
>> +def warn_missing_braces : Warning<
>> +    "suggest braces around initialization of subobject">;
>> 
>> You'll also need InGroup<DiagGroup<"missing-braces">>, DefaultIgnore as part of this, so that the warning is off by default but can be turned on with -Wmissing-braces.
>> 
>> The missing-braces group should also be added to -Wall (in include/clang/Basic/DiagnosticGroups.td), since GCC enables this warning as part of -Wall.
>> 
>> +  
>> +  // Warn about missing braces.
>> +  if (T->isArrayType()) {
>> 
>> Why restrict this warning to array types? GCC diagnoses struct/union types as well.
>> 
>> +    SemaRef.Diag(StructuredSubobjectInitList->getLocStart(), 
>> +                     +                 diag::warn_missing_braces)
>> +    << StructuredSubobjectInitList->getSourceRange()
>> +    << CodeModificationHint::CreateInsertion(
>> +                                    StructuredSubobjectInitList->getLocStart(), 
>> +                                             llvm::StringRef("{"))
>> +    << CodeModificationHint::CreateInsertion(
>> +                                    StructuredSubobjectInitList->getLocEnd(), 
>> +                                             llvm::StringRef("}"));
>> +  }
>> 
>> getLocEnd() is going to point at the first character in the last token of the subobject initialization, so the '}' will be inserted in the wrong place. Use Preprocessor::getLocForEndOfToken() to adjust getLocEnd() to point just past the last character in the last token of the subobject initialization, which is the correct insertion point.
>> 
>> 	- Doug
> 





More information about the cfe-commits mailing list