summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2017-05-22 13:58:16 +0000
committerAlexander Kornienko <alexfh@google.com>2017-05-22 13:58:16 +0000
commita0ddf5fc1c16e89ee1b382a0597050182f9f5a99 (patch)
treed9efb78121e81c5f3795d806789b1d75c383ade4 /clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
parent68ae83e68c6f1f874c162c9bcf032bf305724bab (diff)
downloadbcm5719-llvm-a0ddf5fc1c16e89ee1b382a0597050182f9f5a99.tar.gz
bcm5719-llvm-a0ddf5fc1c16e89ee1b382a0597050182f9f5a99.zip
[clang-tidy] readability-braces-around-statements false positive with char literals
Summary: Single-line if statements cause a false positive when the last token in the conditional statement is a char constant: ``` if (condition) return 'a'; ``` For some reason `findEndLocation` seems to skips too many (vertical) whitespaces in this case. The same problem already occured with string literals (https://reviews.llvm.org/D25558), and was fixed by adding a special check for this very case. I just extended the condition to also include char constants. No idea what really causes the issue though. Reviewers: alexfh Reviewed By: alexfh Subscribers: xazax.hun, cfe-commits Patch by Florian Gross! Differential Revision: https://reviews.llvm.org/D33354 llvm-svn: 303551
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
index 6f35fe210a8..4a96b19d151 100644
--- a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
@@ -54,14 +54,15 @@ SourceLocation forwardSkipWhitespaceAndComments(SourceLocation Loc,
SourceLocation findEndLocation(SourceLocation LastTokenLoc,
const SourceManager &SM,
const ASTContext *Context) {
- SourceLocation Loc = LastTokenLoc;
+ SourceLocation Loc =
+ Lexer::GetBeginningOfToken(LastTokenLoc, SM, Context->getLangOpts());
// Loc points to the beginning of the last (non-comment non-ws) token
// before end or ';'.
assert(Loc.isValid());
bool SkipEndWhitespaceAndComments = true;
tok::TokenKind TokKind = getTokenKind(Loc, SM, Context);
if (TokKind == tok::NUM_TOKENS || TokKind == tok::semi ||
- TokKind == tok::r_brace || isStringLiteral(TokKind)) {
+ TokKind == tok::r_brace) {
// If we are at ";" or "}", we found the last token. We could use as well
// `if (isa<NullStmt>(S))`, but it wouldn't work for nested statements.
SkipEndWhitespaceAndComments = false;
OpenPOWER on IntegriCloud