Disable clang-tidy Google checkers when not compiling in C++ mode. None of the checkers require additional testing as the tests will not compile for other languages or modes, or the checkers would never match a valid construct.
llvm-svn: 246663
diff --git a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
index 9552e1a..22e2139 100644
--- a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
@@ -20,8 +20,11 @@
namespace google {
void ExplicitConstructorCheck::registerMatchers(MatchFinder *Finder) {
- Finder->addMatcher(constructorDecl(unless(isInstantiated())).bind("ctor"),
- this);
+ // Only register the matchers for C++; the functionality currently does not
+ // provide any benefit to other languages, despite being benign.
+ if (getLangOpts().CPlusPlus)
+ Finder->addMatcher(constructorDecl(unless(isInstantiated())).bind("ctor"),
+ this);
}
// Looks for the token matching the predicate and returns the range of the found
diff --git a/clang-tools-extra/clang-tidy/google/ExplicitMakePairCheck.cpp b/clang-tools-extra/clang-tidy/google/ExplicitMakePairCheck.cpp
index f695906..a07e0ff 100644
--- a/clang-tools-extra/clang-tidy/google/ExplicitMakePairCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/ExplicitMakePairCheck.cpp
@@ -27,6 +27,11 @@
void
ExplicitMakePairCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
+ // Only register the matchers for C++; the functionality currently does not
+ // provide any benefit to other languages, despite being benign.
+ if (!getLangOpts().CPlusPlus)
+ return;
+
// Look for std::make_pair with explicit template args. Ignore calls in
// templates.
Finder->addMatcher(
diff --git a/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp b/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
index 6c38a60..05c94d5 100644
--- a/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp
@@ -22,15 +22,12 @@
using namespace ast_matchers;
void IntegerTypesCheck::registerMatchers(MatchFinder *Finder) {
- // Find all TypeLocs.
- Finder->addMatcher(typeLoc().bind("tl"), this);
+ // Find all TypeLocs. The relevant Style Guide rule only applies to C++.
+ if (getLangOpts().CPlusPlus)
+ Finder->addMatcher(typeLoc().bind("tl"), this);
}
void IntegerTypesCheck::check(const MatchFinder::MatchResult &Result) {
- // The relevant Style Guide rule only applies to C++.
- if (!Result.Context->getLangOpts().CPlusPlus)
- return;
-
auto TL = *Result.Nodes.getNodeAs<TypeLoc>("tl");
SourceLocation Loc = TL.getLocStart();
diff --git a/clang-tools-extra/clang-tidy/google/OverloadedUnaryAndCheck.cpp b/clang-tools-extra/clang-tidy/google/OverloadedUnaryAndCheck.cpp
index 25d84b0..5dad36f 100644
--- a/clang-tools-extra/clang-tidy/google/OverloadedUnaryAndCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/OverloadedUnaryAndCheck.cpp
@@ -21,6 +21,11 @@
void
OverloadedUnaryAndCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
+ // Only register the matchers for C++; the functionality currently does not
+ // provide any benefit to other languages, despite being benign.
+ if (!getLangOpts().CPlusPlus)
+ return;
+
// Match unary methods that overload operator&.
Finder->addMatcher(methodDecl(parameterCountIs(0), hasOverloadedOperatorName(
"&")).bind("overload"),
diff --git a/clang-tools-extra/clang-tidy/google/StringReferenceMemberCheck.cpp b/clang-tools-extra/clang-tidy/google/StringReferenceMemberCheck.cpp
index 5b9d477..b000e30 100644
--- a/clang-tools-extra/clang-tidy/google/StringReferenceMemberCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/StringReferenceMemberCheck.cpp
@@ -21,6 +21,11 @@
void StringReferenceMemberCheck::registerMatchers(
ast_matchers::MatchFinder *Finder) {
+ // Only register the matchers for C++; the functionality currently does not
+ // provide any benefit to other languages, despite being benign.
+ if (!getLangOpts().CPlusPlus)
+ return;
+
// Look for const references to std::string or ::string.
auto String = anyOf(recordDecl(hasName("::std::basic_string")),
recordDecl(hasName("::string")));
diff --git a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp b/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
index 8358cb2..d419a01 100644
--- a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
@@ -21,8 +21,11 @@
void UnnamedNamespaceInHeaderCheck::registerMatchers(
ast_matchers::MatchFinder *Finder) {
- Finder->addMatcher(namespaceDecl(isAnonymous()).bind("anonymousNamespace"),
- this);
+ // Only register the matchers for C++; the functionality currently does not
+ // provide any benefit to other languages, despite being benign.
+ if (getLangOpts().CPlusPlus)
+ Finder->addMatcher(namespaceDecl(isAnonymous()).bind("anonymousNamespace"),
+ this);
}
void
diff --git a/clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp b/clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
index 7a25872..c4a0940 100644
--- a/clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
@@ -21,7 +21,10 @@
void UsingNamespaceDirectiveCheck::registerMatchers(
ast_matchers::MatchFinder *Finder) {
- Finder->addMatcher(usingDirectiveDecl().bind("usingNamespace"), this);
+ // Only register the matchers for C++; the functionality currently does not
+ // provide any benefit to other languages, despite being benign.
+ if (getLangOpts().CPlusPlus)
+ Finder->addMatcher(usingDirectiveDecl().bind("usingNamespace"), this);
}
void