[cfe-commits] [PATCH] missing braces warning

Tanya Lattner lattner at apple.com
Sat Mar 6 18:56:30 PST 2010


Doug,

Attached is the updated patch. If you have time to review before 2.7 branches, I can get it in.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: missingBraces.patch
Type: application/octet-stream
Size: 3238 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100306/a92e7ac1/attachment.obj>
-------------- next part --------------


-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