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;
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")
// 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");
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
--- /dev/null
+// 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
+};