[clang-tidy] Handle template instantiations in modenize-use-default check
authorMalcolm Parsons <malcolm.parsons@gmail.com>
Wed, 16 Nov 2016 09:51:40 +0000 (09:51 +0000)
committerMalcolm Parsons <malcolm.parsons@gmail.com>
Wed, 16 Nov 2016 09:51:40 +0000 (09:51 +0000)
Summary:
Duplicate fixes were being created for explicit template instantiations
of out-of-line constructors or destructors.

Fixes PR30921.

Reviewers: alexfh, aaron.ballman

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D26582

llvm-svn: 287091

clang-tools-extra/clang-tidy/modernize/UseDefaultCheck.cpp
clang-tools-extra/test/clang-tidy/modernize-use-default.cpp

index ce497c8..6092ae6 100644 (file)
@@ -241,6 +241,7 @@ void UseDefaultCheck::check(const MatchFinder::MatchResult &Result) {
   if (SpecialFunctionDecl->isDeleted() ||
       SpecialFunctionDecl->isExplicitlyDefaulted() ||
       SpecialFunctionDecl->isLateTemplateParsed() ||
+      SpecialFunctionDecl->isTemplateInstantiation() ||
       !SpecialFunctionDecl->isUserProvided() || !SpecialFunctionDecl->hasBody())
     return;
 
index 4119a70..6f6f01f 100644 (file)
@@ -124,6 +124,26 @@ public:
   // CHECK-FIXES: ~Temp() = default;
 };
 
+// Class template out of line with explicit instantiation.
+template <class T>
+class TempODef {
+public:
+  TempODef();
+  ~TempODef();
+};
+
+template <class T>
+TempODef<T>::TempODef() {}
+// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use '= default'
+// CHECK-FIXES: TempODef<T>::TempODef() = default;
+template <class T>
+TempODef<T>::~TempODef() {}
+// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use '= default'
+// CHECK-FIXES: TempODef<T>::~TempODef() = default;
+
+template class TempODef<int>;
+template class TempODef<double>;
+
 // Non user-provided constructor/destructor.
 struct Imp {
   int Int;