[clang-tools-extra] r344440 - [clang-tidy] add IgnoreMacros option to modernize-use-equals-delete
Miklos Vajna via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 13 00:58:05 PDT 2018
Author: vmiklos
Date: Sat Oct 13 00:58:05 2018
New Revision: 344440
URL: http://llvm.org/viewvc/llvm-project?rev=344440&view=rev
Log:
[clang-tidy] add IgnoreMacros option to modernize-use-equals-delete
And also enable it by default to be consistent with e.g. modernize-use-using.
This improves consistency inside the check itself as well: both checks are now
disabled in macros by default.
This helps e.g. when running this check on client code where the macro is
provided by the system, so there is no easy way to modify it.
Reviewed By: alexfh
Differential Revision: https://reviews.llvm.org/D53217
Added:
clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete-macros.cpp
Modified:
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.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=344440&r1=344439&r2=344440&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.cpp Sat Oct 13 00:58:05 2018
@@ -21,6 +21,10 @@ namespace modernize {
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 @@ void UseEqualsDeleteCheck::check(const M
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 @@ void UseEqualsDeleteCheck::check(const M
// 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");
Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.h?rev=344440&r1=344439&r2=344440&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEqualsDeleteCheck.h Sat Oct 13 00:58:05 2018
@@ -38,9 +38,14 @@ namespace modernize {
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
Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-equals-delete.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-equals-delete.rst?rev=344440&r1=344439&r2=344440&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-equals-delete.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-equals-delete.rst Sat Oct 13 00:58:05 2018
@@ -23,3 +23,8 @@ all other member functions implemented.
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.
Added: clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete-macros.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete-macros.cpp?rev=344440&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete-macros.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-equals-delete-macros.cpp Sat Oct 13 00:58:05 2018
@@ -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
+};
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=344440&r1=344439&r2=344440&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 Sat Oct 13 00:58:05 2018
@@ -185,3 +185,9 @@ protected:
DISALLOW_COPY_AND_ASSIGN(ProtectedDeletedMacro2);
};
+// This resulted in a warning by default.
+#define MACRO(type) void operator=(type const &)
+class C {
+private:
+ MACRO(C);
+};
More information about the cfe-commits
mailing list