@@ -222,6 +222,19 @@ extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl>
222222extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl>
223223 typeAliasDecl;
224224
225+ // / \brief Matches shadow declarations introduced into a scope by a
226+ // / (resolved) using declaration.
227+ // /
228+ // / Given
229+ // / \code
230+ // / namespace n { int f; }
231+ // / namespace declToImport { using n::f; }
232+ // / \endcode
233+ // / usingShadowDecl()
234+ // / matches \code f \endcode
235+ extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingShadowDecl>
236+ usingShadowDecl;
237+
225238// / Matches type alias template declarations.
226239// /
227240// / typeAliasTemplateDecl() matches
@@ -3740,7 +3753,7 @@ extern const internal::VariadicOperatorMatcherFunc<1, 1> unless;
37403753// / Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
37413754// / Matcher<TagType>, Matcher<TemplateSpecializationType>,
37423755// / Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
3743- // / Matcher<UnresolvedUsingType>
3756+ // / Matcher<UnresolvedUsingType>, Matcher<UsingType>
37443757inline internal::PolymorphicMatcher<
37453758 internal::HasDeclarationMatcher,
37463759 void (internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>
@@ -4375,7 +4388,13 @@ AST_POLYMORPHIC_MATCHER_P(throughUsingDecl,
43754388 AST_POLYMORPHIC_SUPPORTED_TYPES (DeclRefExpr,
43764389 UsingType),
43774390 internal::Matcher<UsingShadowDecl>, Inner) {
4378- const NamedDecl *FoundDecl = Node.getFoundDecl ();
4391+ const NamedDecl *FoundDecl;
4392+ if constexpr (std::is_same_v<NodeType, UsingType>) {
4393+ FoundDecl = Node.getDecl ();
4394+ } else {
4395+ static_assert (std::is_same_v<NodeType, DeclRefExpr>);
4396+ FoundDecl = Node.getFoundDecl ();
4397+ }
43794398 if (const UsingShadowDecl *UsingDecl = dyn_cast<UsingShadowDecl>(FoundDecl))
43804399 return Inner.matches (*UsingDecl, Finder, Builder);
43814400 return false ;
@@ -7004,37 +7023,6 @@ AST_POLYMORPHIC_MATCHER_P2(
70047023 InnerMatcher.matches (Args[Index], Finder, Builder);
70057024}
70067025
7007- // / Matches C or C++ elaborated `TypeLoc`s.
7008- // /
7009- // / Given
7010- // / \code
7011- // / struct s {};
7012- // / struct s ss;
7013- // / \endcode
7014- // / elaboratedTypeLoc()
7015- // / matches the `TypeLoc` of the variable declaration of `ss`.
7016- extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, ElaboratedTypeLoc>
7017- elaboratedTypeLoc;
7018-
7019- // / Matches elaborated `TypeLoc`s that have a named `TypeLoc` matching
7020- // / `InnerMatcher`.
7021- // /
7022- // / Given
7023- // / \code
7024- // / template <typename T>
7025- // / class C {};
7026- // / class C<int> c;
7027- // /
7028- // / class D {};
7029- // / class D d;
7030- // / \endcode
7031- // / elaboratedTypeLoc(hasNamedTypeLoc(templateSpecializationTypeLoc()));
7032- // / matches the `TypeLoc` of the variable declaration of `c`, but not `d`.
7033- AST_MATCHER_P (ElaboratedTypeLoc, hasNamedTypeLoc, internal::Matcher<TypeLoc>,
7034- InnerMatcher) {
7035- return InnerMatcher.matches (Node.getNamedTypeLoc (), Finder, Builder);
7036- }
7037-
70387026// / Matches type \c bool.
70397027// /
70407028// / Given
@@ -7301,7 +7289,7 @@ extern const AstTypeMatcher<DecltypeType> decltypeType;
73017289AST_TYPE_TRAVERSE_MATCHER (hasDeducedType, getDeducedType,
73027290 AST_POLYMORPHIC_SUPPORTED_TYPES (AutoType));
73037291
7304- // / Matches \c DecltypeType or \c UsingType nodes to find the underlying type.
7292+ // / Matches \c QualType nodes to find the underlying type.
73057293// /
73067294// / Given
73077295// / \code
@@ -7311,10 +7299,13 @@ AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
73117299// / decltypeType(hasUnderlyingType(isInteger()))
73127300// / matches the type of "a"
73137301// /
7314- // / Usable as: Matcher<DecltypeType>, Matcher<UsingType>
7315- AST_TYPE_TRAVERSE_MATCHER (hasUnderlyingType, getUnderlyingType,
7316- AST_POLYMORPHIC_SUPPORTED_TYPES (DecltypeType,
7317- UsingType));
7302+ // / Usable as: Matcher<QualType>
7303+ AST_MATCHER_P (Type, hasUnderlyingType, internal::Matcher<QualType>, Inner) {
7304+ QualType QT = Node.getLocallyUnqualifiedSingleStepDesugaredType ();
7305+ if (QT == QualType (&Node, 0 ))
7306+ return false ;
7307+ return Inner.matches (QT, Finder, Builder);
7308+ }
73187309
73197310// / Matches \c FunctionType nodes.
73207311// /
@@ -7593,27 +7584,7 @@ extern const AstTypeMatcher<RecordType> recordType;
75937584// / and \c c.
75947585extern const AstTypeMatcher<TagType> tagType;
75957586
7596- // / Matches types specified with an elaborated type keyword or with a
7597- // / qualified name.
7598- // /
7599- // / Given
7600- // / \code
7601- // / namespace N {
7602- // / namespace M {
7603- // / class D {};
7604- // / }
7605- // / }
7606- // / class C {};
7607- // /
7608- // / class C c;
7609- // / N::M::D d;
7610- // / \endcode
7611- // /
7612- // / \c elaboratedType() matches the type of the variable declarations of both
7613- // / \c c and \c d.
7614- extern const AstTypeMatcher<ElaboratedType> elaboratedType;
7615-
7616- // / Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier,
7587+ // / Matches Types whose qualifier, a NestedNameSpecifier,
76177588// / matches \c InnerMatcher if the qualifier exists.
76187589// /
76197590// / Given
@@ -7628,34 +7599,14 @@ extern const AstTypeMatcher<ElaboratedType> elaboratedType;
76287599// /
76297600// / \c elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N"))))
76307601// / matches the type of the variable declaration of \c d.
7631- AST_MATCHER_P (ElaboratedType , hasQualifier,
7632- internal::Matcher<NestedNameSpecifier>, InnerMatcher) {
7633- if (const NestedNameSpecifier * Qualifier = Node.getQualifier ())
7634- return InnerMatcher.matches (* Qualifier, Finder, Builder);
7602+ AST_MATCHER_P (Type , hasQualifier, internal::Matcher<NestedNameSpecifier> ,
7603+ InnerMatcher) {
7604+ if (NestedNameSpecifier Qualifier = Node.getPrefix ())
7605+ return InnerMatcher.matches (Qualifier, Finder, Builder);
76357606
76367607 return false ;
76377608}
76387609
7639- // / Matches ElaboratedTypes whose named type matches \c InnerMatcher.
7640- // /
7641- // / Given
7642- // / \code
7643- // / namespace N {
7644- // / namespace M {
7645- // / class D {};
7646- // / }
7647- // / }
7648- // / N::M::D d;
7649- // / \endcode
7650- // /
7651- // / \c elaboratedType(namesType(recordType(
7652- // / hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable
7653- // / declaration of \c d.
7654- AST_MATCHER_P (ElaboratedType, namesType, internal::Matcher<QualType>,
7655- InnerMatcher) {
7656- return InnerMatcher.matches (Node.getNamedType (), Finder, Builder);
7657- }
7658-
76597610// / Matches types specified through a using declaration.
76607611// /
76617612// / Given
@@ -7824,7 +7775,7 @@ AST_MATCHER_FUNCTION_P_OVERLOAD(
78247775// / matches "A::"
78257776AST_MATCHER_P (NestedNameSpecifier, specifiesType,
78267777 internal::Matcher<QualType>, InnerMatcher) {
7827- if (! Node.getAsType () )
7778+ if (Node.getKind () != NestedNameSpecifier::Kind::Type )
78287779 return false ;
78297780 return InnerMatcher.matches (QualType (Node.getAsType (), 0 ), Finder, Builder);
78307781}
@@ -7842,8 +7793,12 @@ AST_MATCHER_P(NestedNameSpecifier, specifiesType,
78427793// / matches "A::"
78437794AST_MATCHER_P (NestedNameSpecifierLoc, specifiesTypeLoc,
78447795 internal::Matcher<TypeLoc>, InnerMatcher) {
7845- return Node && Node.getNestedNameSpecifier ()->getAsType () &&
7846- InnerMatcher.matches (Node.getTypeLoc (), Finder, Builder);
7796+ if (!Node)
7797+ return false ;
7798+ TypeLoc TL = Node.getAsTypeLoc ();
7799+ if (!TL)
7800+ return false ;
7801+ return InnerMatcher.matches (TL, Finder, Builder);
78477802}
78487803
78497804// / Matches on the prefix of a \c NestedNameSpecifier.
@@ -7858,10 +7813,21 @@ AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
78587813AST_MATCHER_P_OVERLOAD (NestedNameSpecifier, hasPrefix,
78597814 internal::Matcher<NestedNameSpecifier>, InnerMatcher,
78607815 0 ) {
7861- const NestedNameSpecifier *NextNode = Node.getPrefix ();
7816+ NestedNameSpecifier NextNode = std::nullopt ;
7817+ switch (Node.getKind ()) {
7818+ case NestedNameSpecifier::Kind::Namespace:
7819+ NextNode = Node.getAsNamespaceAndPrefix ().Prefix ;
7820+ break ;
7821+ case NestedNameSpecifier::Kind::Type:
7822+ NextNode = Node.getAsType ()->getPrefix ();
7823+ break ;
7824+ default :
7825+ break ;
7826+ }
7827+
78627828 if (!NextNode)
78637829 return false ;
7864- return InnerMatcher.matches (* NextNode, Finder, Builder);
7830+ return InnerMatcher.matches (NextNode, Finder, Builder);
78657831}
78667832
78677833// / Matches on the prefix of a \c NestedNameSpecifierLoc.
@@ -7876,7 +7842,12 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
78767842AST_MATCHER_P_OVERLOAD (NestedNameSpecifierLoc, hasPrefix,
78777843 internal::Matcher<NestedNameSpecifierLoc>, InnerMatcher,
78787844 1 ) {
7879- NestedNameSpecifierLoc NextNode = Node.getPrefix ();
7845+ NestedNameSpecifierLoc NextNode;
7846+ if (TypeLoc TL = Node.getAsTypeLoc ())
7847+ NextNode = TL.getPrefix ();
7848+ else
7849+ NextNode = Node.getAsNamespaceAndPrefix ().Prefix ;
7850+
78807851 if (!NextNode)
78817852 return false ;
78827853 return InnerMatcher.matches (NextNode, Finder, Builder);
@@ -7894,9 +7865,13 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,
78947865// / matches "ns::"
78957866AST_MATCHER_P (NestedNameSpecifier, specifiesNamespace,
78967867 internal::Matcher<NamespaceDecl>, InnerMatcher) {
7897- if (auto *NS = dyn_cast_if_present<NamespaceDecl>(Node.getAsNamespace ()))
7898- return InnerMatcher.matches (*NS, Finder, Builder);
7899- return false ;
7868+ if (Node.getKind () != NestedNameSpecifier::Kind::Namespace)
7869+ return false ;
7870+ const auto *Namespace =
7871+ dyn_cast<NamespaceDecl>(Node.getAsNamespaceAndPrefix ().Namespace );
7872+ if (!Namespace)
7873+ return false ;
7874+ return InnerMatcher.matches (*Namespace, Finder, Builder);
79007875}
79017876
79027877// / Matches attributes.
0 commit comments