Author: alexfh Date: Fri Jul 7 03:15:24 2017 New Revision: 307379 URL: http://llvm.org/viewvc/llvm-project?rev=307379&view=rev Log: [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 Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp?rev=307379&r1=307378&r2=307379&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp Fri Jul 7 03:15:24 2017 @@ -38,11 +38,16 @@ ParseTokens(CharSourceRange Range, const 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())); Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp?rev=307379&r1=307378&r2=307379&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp Fri Jul 7 03:15:24 2017 @@ -12,6 +12,10 @@ struct MUST_USE_RESULT MustUseResultObject {}; +struct IntPair { + int First, Second; +}; + struct Base { virtual ~Base() {} virtual void a(); @@ -41,6 +45,8 @@ struct Base { virtual void ne() noexcept(false); virtual void t() throw(); + + virtual void il(IntPair); }; struct SimpleCases : public Base { @@ -221,6 +227,14 @@ public: // CHECK-FIXES: {{^}} void cv2() const volatile override // some comment }; +struct DefaultArguments : public Base { + // Tests for default arguments (with initializer lists). + // Make sure the override fix is placed after the argument list. + void il(IntPair p = {1, (2 + (3))}) {} + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: annotate this + // CHECK-FIXES: {{^}} void il(IntPair p = {1, (2 + (3))}) override {} +}; + struct Macros : public Base { // Tests for 'virtual' and 'override' being defined through macros. Basically // give up for now. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits