[clang-tools-extra] r302425 - [clang-tidy] Ignore private =deleted methods in macros.

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Mon May 8 07:17:28 PDT 2017


Author: alexfh
Date: Mon May  8 09:17:27 2017
New Revision: 302425

URL: http://llvm.org/viewvc/llvm-project?rev=302425&view=rev
Log:
[clang-tidy] Ignore private =deleted methods in macros.

modernize-use-equals-delete is 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.

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

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.cpp?rev=302425&r1=302424&r2=302425&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.cpp Mon May  8 09:17:27 2017
@@ -57,13 +57,18 @@ void UseEqualsDeleteCheck::check(const M
     SourceLocation EndLoc = Lexer::getLocForEndOfToken(
         Func->getLocEnd(), 0, *Result.SourceManager, getLangOpts());
 
-    // FIXME: Improve FixItHint to make method public
+    // FIXME: Improve FixItHint to make the method public.
     diag(Func->getLocation(),
          "use '= delete' to prohibit calling of a special member function")
         << FixItHint::CreateInsertion(EndLoc, " = delete");
   } else if (const auto *Func =
                  Result.Nodes.getNodeAs<CXXMethodDecl>(DeletedNotPublic)) {
-    // FIXME: Add FixItHint to make method public
+    // 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())
+      return;
+    // FIXME: Add FixItHint to make the method public.
     diag(Func->getLocation(), "deleted member function should be public");
   }
 }

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete.cpp?rev=302425&r1=302424&r2=302425&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete.cpp Mon May  8 09:17:27 2017
@@ -158,3 +158,30 @@ struct PublicDeleted {
 public:
   PublicDeleted(const PublicDeleted &) = delete;
 };
+
+#define M1                                                         \
+  struct PrivateDeletedMacro {                                     \
+  private:                                                         \
+    PrivateDeletedMacro(const PrivateDeletedMacro &) = delete;     \
+  };                                                               \
+  struct ProtectedDeletedMacro {                                   \
+  protected:                                                       \
+    ProtectedDeletedMacro(const ProtectedDeletedMacro &) = delete; \
+  }
+
+M1;
+
+#define DISALLOW_COPY_AND_ASSIGN(name) \
+  name(const name &) = delete;         \
+  void operator=(const name &) = delete
+
+struct PrivateDeletedMacro2 {
+private:
+  DISALLOW_COPY_AND_ASSIGN(PrivateDeletedMacro2);
+};
+
+struct ProtectedDeletedMacro2 {
+protected:
+  DISALLOW_COPY_AND_ASSIGN(ProtectedDeletedMacro2);
+};
+




More information about the cfe-commits mailing list