summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2017-07-07 10:15:24 +0000
committerAlexander Kornienko <alexfh@google.com>2017-07-07 10:15:24 +0000
commit91dafe09b05524d7b102b00a1e82dacbd68f0af7 (patch)
treeeb773425cd8910ae1cfa484624d9ef18be7e357d /clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
parentecedd8d80345ac3ca33c53f3f2599ecc04ea841c (diff)
downloadbcm5719-llvm-91dafe09b05524d7b102b00a1e82dacbd68f0af7.tar.gz
bcm5719-llvm-91dafe09b05524d7b102b00a1e82dacbd68f0af7.zip
[clang-tidy] Fix modernize-use-override incorrect replacement
Summary: For the following code: `modernize-use-override` generates a replacement with incorrect location. ``` struct IntPair { int first, second; }; struct A { virtual void il(IntPair); }; struct B : A { void il(IntPair p = {1, (2 + 3)}) {}; // Generated Fixit: void il(IntPair p = override {1, (2 + 3)}) {}; // Should be: void il(IntPair p = {1, (2 + 3)}) override {}; }; ``` This fixes that and adds a unit test. Reviewers: alexfh, aaron.ballman, hokein Reviewed By: alexfh Subscribers: JDevlieghere, xazax.hun, cfe-commits Tags: #clang-tools-extra Patch by Victor Gao! Differential Revision: https://reviews.llvm.org/D35078 llvm-svn: 307379
Diffstat (limited to 'clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
index f6202c7279b..9429eb2cbf7 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -38,11 +38,16 @@ ParseTokens(CharSourceRange Range, const MatchFinder::MatchResult &Result) {
File.end());
SmallVector<Token, 16> Tokens;
Token Tok;
+ int NestedParens = 0;
while (!RawLexer.LexFromRawLexer(Tok)) {
- if (Tok.is(tok::semi) || Tok.is(tok::l_brace))
+ if ((Tok.is(tok::semi) || Tok.is(tok::l_brace)) && NestedParens == 0)
break;
if (Sources.isBeforeInTranslationUnit(Range.getEnd(), Tok.getLocation()))
break;
+ if (Tok.is(tok::l_paren))
+ ++NestedParens;
+ else if (Tok.is(tok::r_paren))
+ --NestedParens;
if (Tok.is(tok::raw_identifier)) {
IdentifierInfo &Info = Result.Context->Idents.get(StringRef(
Sources.getCharacterData(Tok.getLocation()), Tok.getLength()));
OpenPOWER on IntegriCloud