[clang-tools-extra] r239904 - [clang-tidy] Move user-defined matches to unnamed namespaces to prevent ODR violations.

Alexander Kornienko alexfh at google.com
Wed Jun 17 06:11:38 PDT 2015


Author: alexfh
Date: Wed Jun 17 08:11:37 2015
New Revision: 239904

URL: http://llvm.org/viewvc/llvm-project?rev=239904&view=rev
Log:
[clang-tidy] Move user-defined matches to unnamed namespaces to prevent ODR violations.

Modified:
    clang-tools-extra/trunk/clang-tidy/google/ExplicitMakePairCheck.cpp
    clang-tools-extra/trunk/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
    clang-tools-extra/trunk/clang-tidy/misc/AssertSideEffectCheck.cpp
    clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp
    clang-tools-extra/trunk/clang-tidy/misc/UndelegatedConstructor.cpp
    clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp
    clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
    clang-tools-extra/trunk/clang-tidy/readability/ShrinkToFitCheck.cpp

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=239904&r1=239903&r2=239904&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/ExplicitMakePairCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/ExplicitMakePairCheck.cpp Wed Jun 17 08:11:37 2015
@@ -15,12 +15,11 @@
 using namespace clang::ast_matchers;
 
 namespace clang {
-
-namespace ast_matchers {
+namespace {
 AST_MATCHER(DeclRefExpr, hasExplicitTemplateArgs) {
   return Node.hasExplicitTemplateArgs();
 }
-} // namespace ast_matchers
+} // namespace
 
 namespace tidy {
 namespace google {

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=239904&r1=239903&r2=239904&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp Wed Jun 17 08:11:37 2015
@@ -15,11 +15,11 @@
 using namespace clang::ast_matchers;
 
 namespace clang {
-namespace ast_matchers {
+namespace {
 AST_MATCHER(NamespaceDecl, isAnonymousNamespace) {
   return Node.isAnonymousNamespace();
 }
-} // namespace ast_matchers
+} // namespace
 
 namespace tidy {
 namespace google {

Modified: clang-tools-extra/trunk/clang-tidy/misc/AssertSideEffectCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/AssertSideEffectCheck.cpp?rev=239904&r1=239903&r2=239904&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/AssertSideEffectCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/AssertSideEffectCheck.cpp Wed Jun 17 08:11:37 2015
@@ -21,7 +21,7 @@
 using namespace clang::ast_matchers;
 
 namespace clang {
-namespace ast_matchers {
+namespace {
 
 AST_MATCHER_P(Expr, hasSideEffect, bool, CheckFunctionCalls) {
   const Expr *E = &Node;
@@ -68,7 +68,7 @@ AST_MATCHER_P(Expr, hasSideEffect, bool,
   return isa<CXXNewExpr>(E) || isa<CXXDeleteExpr>(E) || isa<CXXThrowExpr>(E);
 }
 
-} // namespace ast_matchers
+} // namespace
 
 namespace tidy {
 

Modified: clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp?rev=239904&r1=239903&r2=239904&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp Wed Jun 17 08:11:37 2015
@@ -12,14 +12,14 @@
 using namespace clang::ast_matchers;
 
 namespace clang {
-namespace ast_matchers {
+namespace {
 
 AST_MATCHER(CastExpr, isPointerToBoolean) {
   return Node.getCastKind() == CK_PointerToBoolean;
 }
 AST_MATCHER(QualType, isBoolean) { return Node->isBooleanType(); }
 
-} // namespace ast_matchers
+} // namespace
 
 namespace tidy {
 namespace misc {

Modified: clang-tools-extra/trunk/clang-tidy/misc/UndelegatedConstructor.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UndelegatedConstructor.cpp?rev=239904&r1=239903&r2=239904&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UndelegatedConstructor.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UndelegatedConstructor.cpp Wed Jun 17 08:11:37 2015
@@ -15,9 +15,9 @@ using namespace clang::ast_matchers;
 
 namespace clang {
 
-namespace ast_matchers {
-AST_MATCHER_P(Stmt, ignoringTemporaryExpr, internal::Matcher<Stmt>,
-              InnerMatcher) {
+namespace {
+AST_MATCHER_P(Stmt, ignoringTemporaryExpr,
+              ast_matchers::internal::Matcher<Stmt>, InnerMatcher) {
   const Stmt *E = &Node;
   for (;;) {
     // Temporaries with non-trivial dtors.
@@ -38,12 +38,13 @@ AST_MATCHER_P(Stmt, ignoringTemporaryExp
 
 // Finds a node if it's a base of an already bound node.
 AST_MATCHER_P(CXXRecordDecl, baseOfBoundNode, std::string, ID) {
-  return Builder->removeBindings([&](const internal::BoundNodesMap &Nodes) {
-    const auto *Derived = Nodes.getNodeAs<CXXRecordDecl>(ID);
-    return Derived != &Node && !Derived->isDerivedFrom(&Node);
-  });
+  return Builder->removeBindings(
+      [&](const ast_matchers::internal::BoundNodesMap &Nodes) {
+        const auto *Derived = Nodes.getNodeAs<CXXRecordDecl>(ID);
+        return Derived != &Node && !Derived->isDerivedFrom(&Node);
+      });
 }
-} // namespace ast_matchers
+} // namespace
 
 namespace tidy {
 namespace misc {

Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp?rev=239904&r1=239903&r2=239904&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedRAIICheck.cpp Wed Jun 17 08:11:37 2015
@@ -14,12 +14,12 @@
 using namespace clang::ast_matchers;
 
 namespace clang {
-namespace ast_matchers {
+namespace {
 AST_MATCHER(CXXRecordDecl, hasNonTrivialDestructor) {
   // TODO: If the dtor is there but empty we don't want to warn either.
   return Node.hasDefinition() && Node.hasNonTrivialDestructor();
 }
-} // namespace ast_matchers
+} // namespace
 
 namespace tidy {
 namespace misc {

Modified: clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp?rev=239904&r1=239903&r2=239904&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp Wed Jun 17 08:11:37 2015
@@ -38,16 +38,14 @@ static bool isContainer(llvm::StringRef
 }
 
 namespace clang {
-namespace ast_matchers {
+namespace {
 AST_MATCHER(QualType, isBoolType) { return Node->isBooleanType(); }
 
 AST_MATCHER(NamedDecl, stlContainer) {
   return isContainer(Node.getQualifiedNameAsString());
 }
-} // namespace ast_matchers
-} // namespace clang
+} // namespace
 
-namespace clang {
 namespace tidy {
 namespace readability {
 

Modified: clang-tools-extra/trunk/clang-tidy/readability/ShrinkToFitCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ShrinkToFitCheck.cpp?rev=239904&r1=239903&r2=239904&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/ShrinkToFitCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ShrinkToFitCheck.cpp Wed Jun 17 08:11:37 2015
@@ -15,7 +15,9 @@
 
 using namespace clang::ast_matchers;
 
-static bool isShrinkableContainer(llvm::StringRef ClassName) {
+namespace clang {
+namespace {
+bool isShrinkableContainer(llvm::StringRef ClassName) {
   static const char *Shrinkables[] = {
     "std::basic_string",
     "std::deque",
@@ -25,15 +27,11 @@ static bool isShrinkableContainer(llvm::
                             ClassName);
 }
 
-namespace clang {
-namespace ast_matchers {
 AST_MATCHER(NamedDecl, stlShrinkableContainer) {
   return isShrinkableContainer(Node.getQualifiedNameAsString());
 }
-} // namespace ast_matchers
-} // namespace clang
+} // namespace
 
-namespace clang {
 namespace tidy {
 namespace readability {
 





More information about the cfe-commits mailing list