[clang-tidy] Ignore template instantiations in modernize-use-equals-delete check
authorMalcolm Parsons <malcolm.parsons@gmail.com>
Thu, 17 Nov 2016 11:40:02 +0000 (11:40 +0000)
committerMalcolm Parsons <malcolm.parsons@gmail.com>
Thu, 17 Nov 2016 11:40:02 +0000 (11:40 +0000)
Summary: Template instantiations were causing misplaced fixits.

Reviewers: aaron.ballman, alexfh, hokein

Subscribers: hokein, cfe-commits

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

llvm-svn: 287221

clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
clang-tools-extra/test/clang-tidy/modernize-use-equals-delete.cpp

index 3500398..0ac0801 100644 (file)
@@ -34,6 +34,7 @@ void UseEqualsDeleteCheck::registerMatchers(MatchFinder *Finder) {
       cxxMethodDecl(
           PrivateSpecialFn,
           unless(anyOf(hasBody(stmt()), isDefaulted(), isDeleted(),
+                       ast_matchers::isTemplateInstantiation(),
                        // Ensure that all methods except private special member
                        // functions are defined.
                        hasParent(cxxRecordDecl(hasMethod(unless(
index f6cc310..33a0f72 100644 (file)
@@ -22,6 +22,32 @@ private:
   // CHECK-FIXES: ~PositivePrivate() = delete;
 };
 
+template<typename T>
+struct PositivePrivateTemplate {
+private:
+  PositivePrivateTemplate();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivateTemplate() = delete;
+  PositivePrivateTemplate(const PositivePrivateTemplate &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivateTemplate(const PositivePrivateTemplate &) = delete;
+  PositivePrivateTemplate &operator=(const PositivePrivateTemplate &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivateTemplate &operator=(const PositivePrivateTemplate &) = delete;
+  PositivePrivateTemplate(PositivePrivateTemplate &&);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivateTemplate(PositivePrivateTemplate &&) = delete;
+  PositivePrivateTemplate &operator=(PositivePrivateTemplate &&);
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivateTemplate &operator=(PositivePrivateTemplate &&) = delete;
+  ~PositivePrivateTemplate();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: ~PositivePrivateTemplate() = delete;
+};
+
+template struct PositivePrivateTemplate<int>;
+template struct PositivePrivateTemplate<char>;
+
 struct NegativePublic {
   NegativePublic(const NegativePublic &);
 };