[PATCH] D35078: [clang-tidy] Fix modernize-use-override incorrect replacement
Alexander Kornienko via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 7 03:15:57 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307379: [clang-tidy] Fix modernize-use-override incorrect replacement (authored by alexfh).
Changed prior to commit:
https://reviews.llvm.org/D35078?vs=105554&id=105610#toc
Repository:
rL LLVM
https://reviews.llvm.org/D35078
Files:
clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
Index: clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -38,11 +38,16 @@
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()));
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-override.cpp
@@ -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 @@
virtual void ne() noexcept(false);
virtual void t() throw();
+
+ virtual void il(IntPair);
};
struct SimpleCases : public Base {
@@ -221,6 +227,14 @@
// 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35078.105610.patch
Type: text/x-patch
Size: 2189 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170707/c43dc41c/attachment.bin>
More information about the cfe-commits
mailing list