[clang-tools-extra] r246663 - 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.

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 2 09:20:42 PDT 2015


Author: aaronballman
Date: Wed Sep  2 11:20:42 2015
New Revision: 246663

URL: http://llvm.org/viewvc/llvm-project?rev=246663&view=rev
Log:
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.

Modified:
    clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp
    clang-tools-extra/trunk/clang-tidy/google/ExplicitMakePairCheck.cpp
    clang-tools-extra/trunk/clang-tidy/google/IntegerTypesCheck.cpp
    clang-tools-extra/trunk/clang-tidy/google/OverloadedUnaryAndCheck.cpp
    clang-tools-extra/trunk/clang-tidy/google/StringReferenceMemberCheck.cpp
    clang-tools-extra/trunk/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
    clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp?rev=246663&r1=246662&r2=246663&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp Wed Sep  2 11:20:42 2015
@@ -20,8 +20,11 @@ namespace tidy {
 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

Modified: clang-tools-extra/trunk/clang-tidy/google/ExplicitMakePairCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/ExplicitMakePairCheck.cpp?rev=246663&r1=246662&r2=246663&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/ExplicitMakePairCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/ExplicitMakePairCheck.cpp Wed Sep  2 11:20:42 2015
@@ -27,6 +27,11 @@ namespace build {
 
 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(

Modified: clang-tools-extra/trunk/clang-tidy/google/IntegerTypesCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/IntegerTypesCheck.cpp?rev=246663&r1=246662&r2=246663&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/IntegerTypesCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/IntegerTypesCheck.cpp Wed Sep  2 11:20:42 2015
@@ -22,15 +22,12 @@ namespace runtime {
 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();
 

Modified: clang-tools-extra/trunk/clang-tidy/google/OverloadedUnaryAndCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/OverloadedUnaryAndCheck.cpp?rev=246663&r1=246662&r2=246663&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/OverloadedUnaryAndCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/OverloadedUnaryAndCheck.cpp Wed Sep  2 11:20:42 2015
@@ -21,6 +21,11 @@ namespace runtime {
 
 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"),

Modified: clang-tools-extra/trunk/clang-tidy/google/StringReferenceMemberCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/StringReferenceMemberCheck.cpp?rev=246663&r1=246662&r2=246663&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/StringReferenceMemberCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/StringReferenceMemberCheck.cpp Wed Sep  2 11:20:42 2015
@@ -21,6 +21,11 @@ namespace runtime {
 
 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")));

Modified: clang-tools-extra/trunk/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp?rev=246663&r1=246662&r2=246663&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp Wed Sep  2 11:20:42 2015
@@ -21,8 +21,11 @@ namespace build {
 
 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

Modified: clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp?rev=246663&r1=246662&r2=246663&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp Wed Sep  2 11:20:42 2015
@@ -21,7 +21,10 @@ namespace build {
 
 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




More information about the cfe-commits mailing list