From b34b6ffa9d4aae16272cbdbf508134f98b4647d4 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Thu, 22 Nov 2018 16:10:18 +0000 Subject: [clang-tidy] Ignore template instantiations in modernize-use-using The test I'm adding passes without the change due to the deduplication logic in ClangTidyDiagnosticConsumer::take(). However this bug manifests in our internal integration with clang-tidy. I've verified the fix by locally changing LessClangTidyError to consider replacements. llvm-svn: 347470 --- .../clang-tidy/modernize/UseUsingCheck.cpp | 3 ++- .../test/clang-tidy/modernize-use-using.cpp | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp index 5244aa60ee6..a690e447b84 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp @@ -24,7 +24,8 @@ UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context) void UseUsingCheck::registerMatchers(MatchFinder *Finder) { if (!getLangOpts().CPlusPlus11) return; - Finder->addMatcher(typedefDecl().bind("typedef"), this); + Finder->addMatcher(typedefDecl(unless(isInstantiated())).bind("typedef"), + this); } // Checks if 'typedef' keyword can be removed - we do it only if diff --git a/clang-tools-extra/test/clang-tidy/modernize-use-using.cpp b/clang-tools-extra/test/clang-tidy/modernize-use-using.cpp index e8f4958f951..efa4030d001 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-use-using.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-use-using.cpp @@ -162,3 +162,24 @@ typedef unsigned Map[lol]; typedef void (*fun_type)(); // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' // CHECK-FIXES: using fun_type = void (*)(); + +namespace template_instantiations { +template +class C { + protected: + typedef C super; + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' + // CHECK-FIXES: using super = C; + virtual void f(); + +public: + virtual ~C(); +}; + +class D : public C { + void f() override { super::f(); } +}; +class E : public C { + void f() override { super::f(); } +}; +} -- cgit v1.2.3