diff options
author | Alexander Kornienko <alexfh@google.com> | 2015-09-09 17:06:09 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2015-09-09 17:06:09 +0000 |
commit | ffc277989be5531ebf3f2a6b023f54d7929067b9 (patch) | |
tree | 1f3f18678530c7d1f431328368eb2d62befab6ed /clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp | |
parent | ef67d768691f7dd2c69f455f5d4479608eba792f (diff) | |
download | bcm5719-llvm-ffc277989be5531ebf3f2a6b023f54d7929067b9.tar.gz bcm5719-llvm-ffc277989be5531ebf3f2a6b023f54d7929067b9.zip |
[clang-tidy] Fix PR22785.
Fix http://llvm.org/PR22785. Bug 22785 - readability-braces-around-statements
doesn't work well with macros.
http://reviews.llvm.org/D12729
Patch by Marek Kurdej!
llvm-svn: 247163
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp index 350fa8120f0..39534e26ee4 100644 --- a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp @@ -172,7 +172,7 @@ SourceLocation BracesAroundStatementsCheck::findRParenLoc(const IfOrWhileStmt *S, const SourceManager &SM, const ASTContext *Context) { - // Skip macros + // Skip macros. if (S->getLocStart().isMacroID()) return SourceLocation(); @@ -219,13 +219,17 @@ bool BracesAroundStatementsCheck::checkStmt( // Already inside braces. return false; } - // Skip macros. - if (S->getLocStart().isMacroID()) - return false; const SourceManager &SM = *Result.SourceManager; const ASTContext *Context = Result.Context; + // Treat macros. + CharSourceRange FileRange = Lexer::makeFileCharRange( + CharSourceRange::getTokenRange(S->getSourceRange()), SM, + Context->getLangOpts()); + if (FileRange.isInvalid()) + return false; + // InitialLoc points at the last token before opening brace to be inserted. assert(InitialLoc.isValid()); SourceLocation StartLoc = @@ -237,7 +241,8 @@ bool BracesAroundStatementsCheck::checkStmt( EndLoc = EndLocHint; ClosingInsertion = "} "; } else { - EndLoc = findEndLocation(S->getLocEnd(), SM, Context); + const auto FREnd = FileRange.getEnd().getLocWithOffset(-1); + EndLoc = findEndLocation(FREnd, SM, Context); ClosingInsertion = "\n}"; } |