diff options
author | Samuel Benzaquen <sbenza@google.com> | 2015-06-04 16:36:58 +0000 |
---|---|---|
committer | Samuel Benzaquen <sbenza@google.com> | 2015-06-04 16:36:58 +0000 |
commit | cfacf8ae9ec6724a291600b848fbbb94bb5435e5 (patch) | |
tree | d6d2f43b3adf09ba141ea98d088d1a64b889eee1 /clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp | |
parent | 73e06fa262a1c05a09e53e6d5394b73ea875c285 (diff) | |
download | bcm5719-llvm-cfacf8ae9ec6724a291600b848fbbb94bb5435e5.tar.gz bcm5719-llvm-cfacf8ae9ec6724a291600b848fbbb94bb5435e5.zip |
[clang-tidy] Force braces around leaf 'else if' for consistency.
Summary:
Force braces around leaf 'else if' for consistency.
This complements r233697.
Reviewers: alexfh
Subscribers: curdeius, cfe-commits
Differential Revision: http://reviews.llvm.org/D10245
llvm-svn: 239054
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp index 6a95a5f2a6a..350fa8120f0 100644 --- a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp @@ -151,11 +151,15 @@ BracesAroundStatementsCheck::check(const MatchFinder::MatchResult &Result) { SourceLocation StartLoc = findRParenLoc(S, SM, Context); if (StartLoc.isInvalid()) return; + if (ForceBracesStmts.erase(S)) + ForceBracesStmts.insert(S->getThen()); bool BracedIf = checkStmt(Result, S->getThen(), StartLoc, S->getElseLoc()); const Stmt *Else = S->getElse(); + if (Else && BracedIf) + ForceBracesStmts.insert(Else); if (Else && !isa<IfStmt>(Else)) { // Omit 'else if' statements here, they will be handled directly. - checkStmt(Result, Else, S->getElseLoc(), SourceLocation(), BracedIf); + checkStmt(Result, Else, S->getElseLoc(), SourceLocation()); } } else { llvm_unreachable("Invalid match"); @@ -203,7 +207,7 @@ BracesAroundStatementsCheck::findRParenLoc(const IfOrWhileStmt *S, /// Returns true if braces where added. bool BracesAroundStatementsCheck::checkStmt( const MatchFinder::MatchResult &Result, const Stmt *S, - SourceLocation InitialLoc, SourceLocation EndLocHint, bool ForceBraces) { + SourceLocation InitialLoc, SourceLocation EndLocHint) { // 1) If there's a corresponding "else" or "while", the check inserts "} " // right before that token. // 2) If there's a multi-line block comment starting on the same line after @@ -241,7 +245,7 @@ bool BracesAroundStatementsCheck::checkStmt( assert(EndLoc.isValid()); // Don't require braces for statements spanning less than certain number of // lines. - if (ShortStatementLines && !ForceBraces) { + if (ShortStatementLines && !ForceBracesStmts.erase(S)) { unsigned StartLine = SM.getSpellingLineNumber(StartLoc); unsigned EndLine = SM.getSpellingLineNumber(EndLoc); if (EndLine - StartLine < ShortStatementLines) @@ -254,6 +258,10 @@ bool BracesAroundStatementsCheck::checkStmt( return true; } +void BracesAroundStatementsCheck::onEndOfTranslationUnit() { + ForceBracesStmts.clear(); +} + } // namespace readability } // namespace tidy } // namespace clang |