[clang-tools-extra] r325467 - [tidy] Move private ast matchers into anonymous namespaces to avoid ODR conflicts.
Benjamin Kramer via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 18 11:02:35 PST 2018
Author: d0k
Date: Sun Feb 18 11:02:35 2018
New Revision: 325467
URL: http://llvm.org/viewvc/llvm-project?rev=325467&view=rev
Log:
[tidy] Move private ast matchers into anonymous namespaces to avoid ODR conflicts.
No functionality change intended.
Modified:
clang-tools-extra/trunk/clang-tidy/boost/UseToStringCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/VirtualNearMissCheck.cpp
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
clang-tools-extra/trunk/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp
clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp
clang-tools-extra/trunk/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp
clang-tools-extra/trunk/clang-tidy/hicpp/NoAssemblerCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
Modified: clang-tools-extra/trunk/clang-tidy/boost/UseToStringCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/boost/UseToStringCheck.cpp?rev=325467&r1=325466&r2=325467&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/boost/UseToStringCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/boost/UseToStringCheck.cpp Sun Feb 18 11:02:35 2018
@@ -15,10 +15,12 @@ namespace clang {
namespace tidy {
namespace boost {
+namespace {
AST_MATCHER(Type, isStrictlyInteger) {
return Node.isIntegerType() && !Node.isAnyCharacterType() &&
!Node.isBooleanType();
}
+} // namespace
void UseToStringCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
Modified: clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp?rev=325467&r1=325466&r2=325467&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/StringConstructorCheck.cpp Sun Feb 18 11:02:35 2018
@@ -18,9 +18,11 @@ namespace clang {
namespace tidy {
namespace bugprone {
+namespace {
AST_MATCHER_P(IntegerLiteral, isBiggerThan, unsigned, N) {
return Node.getValue().getZExtValue() > N;
}
+} // namespace
StringConstructorCheck::StringConstructorCheck(StringRef Name,
ClangTidyContext *Context)
Modified: clang-tools-extra/trunk/clang-tidy/bugprone/VirtualNearMissCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/VirtualNearMissCheck.cpp?rev=325467&r1=325466&r2=325467&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/bugprone/VirtualNearMissCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/VirtualNearMissCheck.cpp Sun Feb 18 11:02:35 2018
@@ -19,11 +19,13 @@ namespace clang {
namespace tidy {
namespace bugprone {
+namespace {
AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
AST_MATCHER(CXXMethodDecl, isOverloadedOperator) {
return Node.isOverloadedOperator();
}
+} // namespace
/// Finds out if the given method overrides some method.
static bool isOverrideMethod(const CXXMethodDecl *MD) {
Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp?rev=325467&r1=325466&r2=325467&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp Sun Feb 18 11:02:35 2018
@@ -17,9 +17,11 @@ namespace clang {
namespace tidy {
namespace cppcoreguidelines {
+namespace {
AST_MATCHER(GotoStmt, isForwardJumping) {
return Node.getLocStart() < Node.getLabel()->getLocStart();
}
+} // namespace
void AvoidGotoCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp?rev=325467&r1=325466&r2=325467&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp Sun Feb 18 11:02:35 2018
@@ -17,6 +17,7 @@ namespace clang {
namespace tidy {
namespace cppcoreguidelines {
+namespace {
AST_MATCHER_P(CXXForRangeStmt, hasRangeBeginEndStmt,
ast_matchers::internal::Matcher<DeclStmt>, InnerMatcher) {
for (const DeclStmt *Stmt : {Node.getBeginStmt(), Node.getEndStmt()})
@@ -46,6 +47,7 @@ AST_MATCHER_P(Expr, hasParentIgnoringImp
return InnerMatcher.matches(*E, Finder, Builder);
}
+} // namespace
void ProBoundsArrayToPointerDecayCheck::registerMatchers(MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus)
Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp?rev=325467&r1=325466&r2=325467&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp Sun Feb 18 11:02:35 2018
@@ -17,12 +17,14 @@ using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
namespace fuchsia {
-
+
+namespace {
AST_MATCHER(CXXRecordDecl, hasBases) {
if (Node.hasDefinition())
return Node.getNumBases() > 0;
return false;
}
+} // namespace
// Adds a node (by name) to the interface map, if it was not present in the map
// previously.
Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp?rev=325467&r1=325466&r2=325467&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp Sun Feb 18 11:02:35 2018
@@ -15,6 +15,7 @@ namespace clang {
namespace tidy {
namespace fuchsia {
+namespace {
AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) {
if (const auto *CXXMethodNode = dyn_cast<CXXMethodDecl>(&Node)) {
if (CXXMethodNode->isCopyAssignmentOperator() ||
@@ -23,6 +24,7 @@ AST_MATCHER(FunctionDecl, isFuchsiaOverl
}
return Node.isOverloadedOperator();
}
+} // namespace
void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator()).bind("decl"),
Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp?rev=325467&r1=325466&r2=325467&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp Sun Feb 18 11:02:35 2018
@@ -14,7 +14,8 @@ using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
namespace fuchsia {
-
+
+namespace {
AST_MATCHER(Expr, isConstantInitializer) {
return Node.isConstantInitializer(Finder->getASTContext(), false);
}
@@ -22,7 +23,8 @@ AST_MATCHER(Expr, isConstantInitializer)
AST_MATCHER(VarDecl, isGlobalStatic) {
return Node.getStorageDuration() == SD_Static && !Node.isLocalVarDecl();
}
-
+} // namespace
+
void StaticallyConstructedObjectsCheck::registerMatchers(MatchFinder *Finder) {
// Constructing global, non-trivial objects with static storage is
// disallowed, unless the object is statically initialized with a constexpr
Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp?rev=325467&r1=325466&r2=325467&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp Sun Feb 18 11:02:35 2018
@@ -15,18 +15,16 @@
using namespace clang::ast_matchers;
namespace clang {
-namespace ast_matchers {
-
-const internal::VariadicDynCastAllOfMatcher<Type, DecltypeType> decltypeType;
-
-} // namespace ast_matchers
-
namespace tidy {
namespace fuchsia {
+namespace {
+const internal::VariadicDynCastAllOfMatcher<Type, DecltypeType> decltypeType;
+
AST_MATCHER(FunctionDecl, hasTrailingReturn) {
return Node.getType()->castAs<FunctionProtoType>()->hasTrailingReturn();
}
+} // namespace
void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) {
Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp?rev=325467&r1=325466&r2=325467&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/VirtualInheritanceCheck.cpp Sun Feb 18 11:02:35 2018
@@ -17,6 +17,7 @@ namespace clang {
namespace tidy {
namespace fuchsia {
+namespace {
AST_MATCHER(CXXRecordDecl, hasDirectVirtualBaseClass) {
if (!Node.hasDefinition()) return false;
if (!Node.getNumVBases()) return false;
@@ -24,6 +25,7 @@ AST_MATCHER(CXXRecordDecl, hasDirectVirt
if (Base.isVirtual()) return true;
return false;
}
+} // namespace
void VirtualInheritanceCheck::registerMatchers(MatchFinder *Finder) {
// Defining classes using direct virtual inheritance is disallowed.
Modified: clang-tools-extra/trunk/clang-tidy/hicpp/NoAssemblerCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/NoAssemblerCheck.cpp?rev=325467&r1=325466&r2=325467&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/hicpp/NoAssemblerCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/NoAssemblerCheck.cpp Sun Feb 18 11:02:35 2018
@@ -14,17 +14,16 @@
using namespace clang::ast_matchers;
namespace clang {
-namespace ast_matchers {
-AST_MATCHER(VarDecl, isAsm) { return Node.hasAttr<clang::AsmLabelAttr>(); }
-const internal::VariadicDynCastAllOfMatcher<Decl, FileScopeAsmDecl>
- fileScopeAsmDecl;
-}
-}
-
-namespace clang {
namespace tidy {
namespace hicpp {
+namespace {
+AST_MATCHER(VarDecl, isAsm) { return Node.hasAttr<clang::AsmLabelAttr>(); }
+const ast_matchers::internal::VariadicDynCastAllOfMatcher<Decl,
+ FileScopeAsmDecl>
+ fileScopeAsmDecl;
+} // namespace
+
void NoAssemblerCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(asmStmt().bind("asm-stmt"), this);
Finder->addMatcher(fileScopeAsmDecl().bind("asm-file-scope"), this);
Modified: clang-tools-extra/trunk/clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp?rev=325467&r1=325466&r2=325467&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp Sun Feb 18 11:02:35 2018
@@ -17,12 +17,14 @@ namespace clang {
namespace tidy {
namespace misc {
+namespace {
AST_MATCHER(StringLiteral, containsNul) {
for (size_t i = 0; i < Node.getLength(); ++i)
if (Node.getCodeUnit(i) == '\0')
return true;
return false;
}
+} // namespace
void StringLiteralWithEmbeddedNulCheck::registerMatchers(MatchFinder *Finder) {
// Match a string that contains embedded NUL character. Extra-checks are
Modified: clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp?rev=325467&r1=325466&r2=325467&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp Sun Feb 18 11:02:35 2018
@@ -23,6 +23,7 @@ namespace clang {
namespace tidy {
namespace modernize {
+namespace {
/// \brief Matches move-constructible classes.
///
/// Given
@@ -44,6 +45,7 @@ AST_MATCHER(CXXRecordDecl, isMoveConstru
}
return false;
}
+} // namespace
static TypeMatcher constRefType() {
return lValueReferenceType(pointee(isConstQualified()));
Modified: clang-tools-extra/trunk/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp?rev=325467&r1=325466&r2=325467&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp Sun Feb 18 11:02:35 2018
@@ -21,6 +21,7 @@ namespace clang {
namespace tidy {
namespace modernize {
+namespace {
static const char AutoPtrTokenId[] = "AutoPrTokenId";
static const char AutoPtrOwnershipTransferId[] = "AutoPtrOwnershipTransferId";
@@ -69,6 +70,8 @@ AST_MATCHER(Decl, isFromStdNamespace) {
return (Info && Info->isStr("std"));
}
+} // namespace
+
ReplaceAutoPtrCheck::ReplaceAutoPtrCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
More information about the cfe-commits
mailing list