[PATCH] D53217: [clang-tidy] add IgnoreMacros option to modernize-use-equals-delete

Miklos Vajna via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 13 01:00:35 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL344440: [clang-tidy] add IgnoreMacros option to modernize-use-equals-delete (authored by vmiklos, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D53217?vs=169490&id=169551#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D53217

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
  clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.h
  clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-equals-delete.rst
  clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete-macros.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete.cpp


Index: clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.h
===================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.h
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.h
@@ -38,9 +38,14 @@
 class UseEqualsDeleteCheck : public ClangTidyCheck {
 public:
   UseEqualsDeleteCheck(StringRef Name, ClangTidyContext *Context)
-      : ClangTidyCheck(Name, Context) {}
+      : ClangTidyCheck(Name, Context),
+        IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", 1) != 0) {}
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  const bool IgnoreMacros;
 };
 
 } // namespace modernize
Index: clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
@@ -21,6 +21,10 @@
 static const char SpecialFunction[] = "SpecialFunction";
 static const char DeletedNotPublic[] = "DeletedNotPublic";
 
+void UseEqualsDeleteCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IgnoreMacros", IgnoreMacros);
+}
+
 void UseEqualsDeleteCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus)
     return;
@@ -57,6 +61,8 @@
     SourceLocation EndLoc = Lexer::getLocForEndOfToken(
         Func->getEndLoc(), 0, *Result.SourceManager, getLangOpts());
 
+    if (Func->getLocation().isMacroID() && IgnoreMacros)
+      return;
     // FIXME: Improve FixItHint to make the method public.
     diag(Func->getLocation(),
          "use '= delete' to prohibit calling of a special member function")
@@ -66,7 +72,7 @@
     // Ignore this warning in macros, since it's extremely noisy in code using
     // DISALLOW_COPY_AND_ASSIGN-style macros and there's no easy way to
     // automatically fix the warning when macros are in play.
-    if (Func->getLocation().isMacroID())
+    if (Func->getLocation().isMacroID() && IgnoreMacros)
       return;
     // FIXME: Add FixItHint to make the method public.
     diag(Func->getLocation(), "deleted member function should be public");
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-equals-delete.rst
===================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-equals-delete.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-equals-delete.rst
@@ -23,3 +23,8 @@
     A& operator=(const A&) = delete;
   };
 
+
+.. option:: IgnoreMacros
+
+   If this option is set to non-zero (default is `1`), the check will not warn
+   about functions declared inside macros.
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete.cpp
@@ -185,3 +185,9 @@
   DISALLOW_COPY_AND_ASSIGN(ProtectedDeletedMacro2);
 };
 
+// This resulted in a warning by default.
+#define MACRO(type) void operator=(type const &)
+class C {
+private:
+  MACRO(C);
+};
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete-macros.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete-macros.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete-macros.cpp
@@ -0,0 +1,10 @@
+// RUN: %check_clang_tidy %s modernize-use-equals-delete %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-equals-delete.IgnoreMacros, value: 0}]}" \
+// RUN:   -- -std=c++11
+
+#define MACRO(type) void operator=(type const &)
+class C {
+private:
+  MACRO(C);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function
+};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53217.169551.patch
Type: text/x-patch
Size: 4206 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181013/cbc3993a/attachment-0001.bin>


More information about the llvm-commits mailing list