diff options
author | Tanya Lattner <tonic@nondot.org> | 2010-03-07 04:17:15 +0000 |
---|---|---|
committer | Tanya Lattner <tonic@nondot.org> | 2010-03-07 04:17:15 +0000 |
commit | 1e1d396dc55002a2a6355048db542a38b5137002 (patch) | |
tree | 490cb6200609068105863e87c681c776585b6a16 /lib/Sema/SemaInit.cpp | |
parent | b196ef78cb3e046a6fea94bde7c361764ab159bd (diff) |
Implement missing-braces warning and add a test case.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97893 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaInit.cpp')
-rw-r--r-- | lib/Sema/SemaInit.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index bf9f73c961..386bb1fea3 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -18,6 +18,7 @@ #include "SemaInit.h" #include "Lookup.h" #include "Sema.h" +#include "clang/Lex/Preprocessor.h" #include "clang/Parse/Designator.h" #include "clang/AST/ASTContext.h" #include "clang/AST/ExprCXX.h" @@ -497,6 +498,20 @@ void InitListChecker::CheckImplicitInitList(const InitializedEntity &Entity, = ParentIList->getInit(EndIndex)->getSourceRange().getEnd(); StructuredSubobjectInitList->setRBraceLoc(EndLoc); } + + // Warn about missing braces. + if (T->isArrayType() || T->isRecordType()) { + SemaRef.Diag(StructuredSubobjectInitList->getLocStart(), + + diag::warn_missing_braces) + << StructuredSubobjectInitList->getSourceRange() + << CodeModificationHint::CreateInsertion( + StructuredSubobjectInitList->getLocStart(), + llvm::StringRef("{")) + << CodeModificationHint::CreateInsertion( + SemaRef.PP.getLocForEndOfToken( +StructuredSubobjectInitList->getLocEnd()), + llvm::StringRef("}")); + } } void InitListChecker::CheckExplicitInitList(const InitializedEntity &Entity, |