[clang-tools-extra] ce619f6 - [NFC][clang-tidy] Use isInStdNamespace matcher instead of check defined alternatives
Nathan James via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 18 08:02:23 PDT 2020
Author: Nathan James
Date: 2020-10-18T16:02:11+01:00
New Revision: ce619f645f58154fcc1d88e9de81aa7903dd7bc0
URL: https://github.com/llvm/llvm-project/commit/ce619f645f58154fcc1d88e9de81aa7903dd7bc0
DIFF: https://github.com/llvm/llvm-project/commit/ce619f645f58154fcc1d88e9de81aa7903dd7bc0.diff
LOG: [NFC][clang-tidy] Use isInStdNamespace matcher instead of check defined alternatives
Added:
Modified:
clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
index 02c9e74c7bb0..2b072172792d 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
@@ -35,40 +35,6 @@ static const char AutoPtrOwnershipTransferId[] = "AutoPtrOwnershipTransferId";
/// \endcode
AST_MATCHER(Expr, isLValue) { return Node.getValueKind() == VK_LValue; }
-/// Matches declarations whose declaration context is the C++ standard library
-/// namespace std.
-///
-/// Note that inline namespaces are silently ignored during the lookup since
-/// both libstdc++ and libc++ are known to use them for versioning purposes.
-///
-/// Given:
-/// \code
-/// namespace ns {
-/// struct my_type {};
-/// using namespace std;
-/// }
-///
-/// using std::vector;
-/// using ns:my_type;
-/// using ns::list;
-/// \code
-///
-/// usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(isFromStdNamespace())))
-/// matches "using std::vector" and "using ns::list".
-AST_MATCHER(Decl, isFromStdNamespace) {
- const DeclContext *D = Node.getDeclContext();
-
- while (D->isInlineNamespace())
- D = D->getParent();
-
- if (!D->isNamespace() || !D->getParent()->isTranslationUnit())
- return false;
-
- const IdentifierInfo *Info = cast<NamespaceDecl>(D)->getIdentifier();
-
- return (Info && Info->isStr("std"));
-}
-
} // namespace
ReplaceAutoPtrCheck::ReplaceAutoPtrCheck(StringRef Name,
@@ -82,7 +48,7 @@ void ReplaceAutoPtrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}
void ReplaceAutoPtrCheck::registerMatchers(MatchFinder *Finder) {
- auto AutoPtrDecl = recordDecl(hasName("auto_ptr"), isFromStdNamespace());
+ auto AutoPtrDecl = recordDecl(hasName("auto_ptr"), isInStdNamespace());
auto AutoPtrType = qualType(hasDeclaration(AutoPtrDecl));
// std::auto_ptr<int> a;
@@ -103,7 +69,7 @@ void ReplaceAutoPtrCheck::registerMatchers(MatchFinder *Finder) {
// using std::auto_ptr;
// ^~~~~~~~~~~~~~~~~~~
Finder->addMatcher(usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(namedDecl(
- hasName("auto_ptr"), isFromStdNamespace()))))
+ hasName("auto_ptr"), isInStdNamespace()))))
.bind(AutoPtrTokenId),
this);
diff --git a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
index 44ae380b63b2..f15b734c55d6 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
@@ -155,40 +155,6 @@ Matcher<NamedDecl> hasStdContainerName() {
return hasAnyName(ContainerNames);
}
-/// Matches declarations whose declaration context is the C++ standard library
-/// namespace std.
-///
-/// Note that inline namespaces are silently ignored during the lookup since
-/// both libstdc++ and libc++ are known to use them for versioning purposes.
-///
-/// Given:
-/// \code
-/// namespace ns {
-/// struct my_type {};
-/// using namespace std;
-/// }
-///
-/// using std::vector;
-/// using ns:my_type;
-/// using ns::list;
-/// \code
-///
-/// usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(isFromStdNamespace())))
-/// matches "using std::vector" and "using ns::list".
-AST_MATCHER(Decl, isFromStdNamespace) {
- const DeclContext *D = Node.getDeclContext();
-
- while (D->isInlineNamespace())
- D = D->getParent();
-
- if (!D->isNamespace() || !D->getParent()->isTranslationUnit())
- return false;
-
- const IdentifierInfo *Info = cast<NamespaceDecl>(D)->getIdentifier();
-
- return (Info && Info->isStr("std"));
-}
-
/// Matches declaration reference or member expressions with explicit template
/// arguments.
AST_POLYMORPHIC_MATCHER(hasExplicitTemplateArgs,
@@ -202,7 +168,7 @@ AST_POLYMORPHIC_MATCHER(hasExplicitTemplateArgs,
DeclarationMatcher standardIterator() {
return decl(
namedDecl(hasStdIteratorName()),
- hasDeclContext(recordDecl(hasStdContainerName(), isFromStdNamespace())));
+ hasDeclContext(recordDecl(hasStdContainerName(), isInStdNamespace())));
}
/// Returns a TypeMatcher that matches typedefs for standard iterators
@@ -226,7 +192,7 @@ TypeMatcher iteratorFromUsingDeclaration() {
// Unwrap the nested name specifier to test for one of the standard
// containers.
hasQualifier(specifiesType(templateSpecializationType(hasDeclaration(
- namedDecl(hasStdContainerName(), isFromStdNamespace()))))),
+ namedDecl(hasStdContainerName(), isInStdNamespace()))))),
// the named type is what comes after the final '::' in the type. It
// should name one of the standard iterator names.
namesType(
More information about the cfe-commits
mailing list