From 7aedf33a241da0c5bffc4d5a9e723bf8291993e5 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Tue, 9 May 2017 12:41:11 +0000 Subject: [PATCH] [clang-tidy] Minor cleanup + a disabled test case for PR26228. NFC llvm-svn: 302522 --- .../clang-tidy/readability/BracesAroundStatementsCheck.cpp | 10 +++++----- .../test/clang-tidy/readability-braces-around-statements.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp index 4dea41d..6f35fe2 100644 --- a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp @@ -39,7 +39,7 @@ SourceLocation forwardSkipWhitespaceAndComments(SourceLocation Loc, const ASTContext *Context) { assert(Loc.isValid()); for (;;) { - while (isWhitespace(*FullSourceLoc(Loc, SM).getCharacterData())) + while (isWhitespace(*SM.getCharacterData(Loc))) Loc = Loc.getLocWithOffset(1); tok::TokenKind TokKind = getTokenKind(Loc, SM, Context); @@ -69,7 +69,6 @@ SourceLocation findEndLocation(SourceLocation LastTokenLoc, Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, Context->getLangOpts()); // Loc points past the last token before end or after ';'. - if (SkipEndWhitespaceAndComments) { Loc = forwardSkipWhitespaceAndComments(Loc, SM, Context); tok::TokenKind TokKind = getTokenKind(Loc, SM, Context); @@ -79,10 +78,11 @@ SourceLocation findEndLocation(SourceLocation LastTokenLoc, for (;;) { assert(Loc.isValid()); - while (isHorizontalWhitespace(*FullSourceLoc(Loc, SM).getCharacterData())) + while (isHorizontalWhitespace(*SM.getCharacterData(Loc))) { Loc = Loc.getLocWithOffset(1); + } - if (isVerticalWhitespace(*FullSourceLoc(Loc, SM).getCharacterData())) { + if (isVerticalWhitespace(*SM.getCharacterData(Loc))) { // EOL, insert brace before. break; } @@ -159,7 +159,7 @@ void BracesAroundStatementsCheck::check( ForceBracesStmts.insert(Else); if (Else && !isa(Else)) { // Omit 'else if' statements here, they will be handled directly. - checkStmt(Result, Else, S->getElseLoc(), SourceLocation()); + checkStmt(Result, Else, S->getElseLoc()); } } else { llvm_unreachable("Invalid match"); diff --git a/clang-tools-extra/test/clang-tidy/readability-braces-around-statements.cpp b/clang-tools-extra/test/clang-tidy/readability-braces-around-statements.cpp index ee147f6..9730735 100644 --- a/clang-tools-extra/test/clang-tidy/readability-braces-around-statements.cpp +++ b/clang-tools-extra/test/clang-tidy/readability-braces-around-statements.cpp @@ -172,6 +172,17 @@ void test() { // CHECK-FIXES-NEXT: } } +void f(const char *p) { + if (!p) + f("\ +"); + // CHECK-MESSAGES: :[[@LINE-3]]:10: warning: statement should be inside braces + // CHECK-FIXES: {{^ }}if (!p) {{{$}} + // CHECK-FIXES-NEXT: {{^ }}f("\{{$}} + // CHECK-FIXES-_NEXT: {{^}}");{{$}} FIXME: This breaks (http://llvm.org/PR26228) + // CHECK-FIXES-_NEXT: {{^}}}{{$}} +} + #define M(x) x int test_macros(bool b) { -- 2.7.4