diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html index ddc99020604c9..8564f2650d205 100644 --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -2536,6 +2536,15 @@
Matches a dependent name type. + +Example matches T::type + + templatestruct declToImport { + typedef typename T::type dependent_name; + }; +
Matches C++17 deduced template specialization types, e.g. deduced class diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 983c1da20ed4c..210ccc16eeb4f 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1110,6 +1110,8 @@ AST Matchers - Add ``dependentScopeDeclRefExpr`` matcher to match expressions that refer to dependent scope declarations. +- Add ``dependentNameType`` matcher to match a dependent name type. + clang-format ------------ diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index 22e2546ab81e0..9a046714068a5 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -7711,6 +7711,16 @@ AST_MATCHER_P(DecayedType, hasDecayedType, internal::Matcher, return InnerType.matches(Node.getDecayedType(), Finder, Builder); } +/// Matches a dependent name type +/// +/// Example matches T::type +/// \code +/// template struct declToImport { +/// typedef typename T::type dependent_name; +/// }; +/// \endcode +extern const AstTypeMatcher dependentNameType; + /// Matches declarations whose declaration context, interpreted as a /// Decl, matches \c InnerMatcher. /// diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp index 8c744eebbdfb5..a47633bf4bae2 100644 --- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp +++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -1108,6 +1108,7 @@ const AstTypeMatcher substTemplateTypeParmType; const AstTypeMatcher templateTypeParmType; const AstTypeMatcher injectedClassNameType; const AstTypeMatcher decayedType; +const AstTypeMatcher dependentNameType; AST_TYPELOC_TRAVERSE_MATCHER_DEF(hasElementType, AST_POLYMORPHIC_SUPPORTED_TYPES(ArrayType, ComplexType)); diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp index 685d626d2978b..bfdee412c5328 100644 --- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp @@ -222,6 +222,7 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(decompositionDecl); REGISTER_MATCHER(declCountIs); REGISTER_MATCHER(declRefExpr); + REGISTER_MATCHER(dependentNameType); REGISTER_MATCHER(dependentScopeDeclRefExpr); REGISTER_MATCHER(declStmt); REGISTER_MATCHER(declaratorDecl); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index ec062a5cc953b..ee1d896f1ca6d 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -3196,9 +3196,6 @@ TEST_P(ImportExpr, DependentScopeDeclRefExpr) { has(callExpr(has(dependentScopeDeclRefExpr()))))))))); } -const internal::VariadicDynCastAllOfMatcher - dependentNameType; - TEST_P(ImportExpr, DependentNameType) { MatchVerifier Verifier; testImport("template struct declToImport {" diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp index a3baad367a27b..b8521e2f95768 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -1912,6 +1912,20 @@ TEST_P(ASTMatchersTest, DeducedTemplateSpecializationType) { deducedTemplateSpecializationType())); } +TEST_P(ASTMatchersTest, DependentNameType) { + if (!GetParam().isCXX()) { + return; + } + + EXPECT_TRUE(matches( + R"( + template struct declToImport { + typedef typename T::type dependent_name; + }; + )", + dependentNameType())); +} + TEST_P(ASTMatchersTest, RecordType) { EXPECT_TRUE(matches("struct S {}; struct S s;", recordType(hasDeclaration(recordDecl(hasName("S"))))));