diff --git a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp index 1605626d1427..220d31c360e4 100644 --- a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp @@ -89,6 +89,10 @@ void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) { if (const auto *Conversion = Result.Nodes.getNodeAs("conversion")) { SourceLocation Loc = Conversion->getLocation(); + // Ignore all macros until we learn to ignore specific ones (e.g. used in + // gmock to define matchers). + if (Loc.isMacroID()) + return; diag(Loc, WarningMessage) << Conversion << FixItHint::CreateInsertion(Loc, "explicit "); return; diff --git a/clang-tools-extra/test/clang-tidy/google-explicit-constructor.cpp b/clang-tools-extra/test/clang-tidy/google-explicit-constructor.cpp index aac6ab62bd2a..4143e937c715 100644 --- a/clang-tools-extra/test/clang-tidy/google-explicit-constructor.cpp +++ b/clang-tools-extra/test/clang-tidy/google-explicit-constructor.cpp @@ -168,5 +168,11 @@ void f2() { if (b) {} (void)(F*)b; (void)(F*)b; - } + +#define DEFINE_STRUCT_WITH_OPERATOR_BOOL(name) \ + struct name { \ + operator bool() const; \ + } + +DEFINE_STRUCT_WITH_OPERATOR_BOOL(H);