forked from OSchip/llvm-project
Implement missing-braces warning and add a test case.
llvm-svn: 97893
This commit is contained in:
parent
03b3eba151
commit
5029d56cc1
|
@ -48,7 +48,7 @@ def : DiagGroup<"init-self">;
|
|||
def : DiagGroup<"inline">;
|
||||
def : DiagGroup<"int-to-pointer-cast">;
|
||||
def : DiagGroup<"invalid-pch">;
|
||||
def : DiagGroup<"missing-braces">;
|
||||
def MissingBraces : DiagGroup<"missing-braces">;
|
||||
def : DiagGroup<"missing-declarations">;
|
||||
def : DiagGroup<"missing-format-attribute">;
|
||||
def : DiagGroup<"missing-include-dirs">;
|
||||
|
@ -156,6 +156,7 @@ def Most : DiagGroup<"most", [
|
|||
Format,
|
||||
Implicit,
|
||||
MismatchedTags,
|
||||
MissingBraces,
|
||||
MultiChar,
|
||||
ReturnType,
|
||||
Switch,
|
||||
|
|
|
@ -1580,6 +1580,9 @@ def err_bitfield_width_exceeds_type_size : Error<
|
|||
"size of bit-field %0 exceeds size of its type (%1 bits)">;
|
||||
def err_anon_bitfield_width_exceeds_type_size : Error<
|
||||
"size of anonymous bit-field exceeds size of its type (%0 bits)">;
|
||||
def warn_missing_braces : Warning<
|
||||
"suggest braces around initialization of subobject">,
|
||||
InGroup<DiagGroup<"missing-braces">>, DefaultIgnore;
|
||||
|
||||
def err_redefinition_of_label : Error<"redefinition of label '%0'">;
|
||||
def err_undeclared_label_use : Error<"use of undeclared label '%0'">;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
// RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
|
||||
|
||||
int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} expected-warning{{suggest braces}}
|
Loading…
Reference in New Issue