Index: include/clang/ASTMatchers/ASTMatchersInternal.h =================================================================== --- include/clang/ASTMatchers/ASTMatchersInternal.h +++ include/clang/ASTMatchers/ASTMatchersInternal.h @@ -741,24 +741,33 @@ /// matcher matches on it. bool matchesSpecialized(const Type &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const { + + // For deduced types, use the deduced type + const Type *EffectiveType = &Node; + if (const auto *S = dyn_cast(&Node)) { + EffectiveType = S->getDeducedType().getTypePtrOrNull(); + if (!EffectiveType) + return false; + } + // First, for any types that have a declaration, extract the declaration and // match on it. - if (const auto *S = dyn_cast(&Node)) { + if (const auto *S = dyn_cast(EffectiveType)) { return matchesDecl(S->getDecl(), Finder, Builder); } - if (const auto *S = dyn_cast(&Node)) { + if (const auto *S = dyn_cast(EffectiveType)) { return matchesDecl(S->getDecl(), Finder, Builder); } - if (const auto *S = dyn_cast(&Node)) { + if (const auto *S = dyn_cast(EffectiveType)) { return matchesDecl(S->getDecl(), Finder, Builder); } - if (const auto *S = dyn_cast(&Node)) { + if (const auto *S = dyn_cast(EffectiveType)) { return matchesDecl(S->getDecl(), Finder, Builder); } - if (const auto *S = dyn_cast(&Node)) { + if (const auto *S = dyn_cast(EffectiveType)) { return matchesDecl(S->getDecl(), Finder, Builder); } - if (const auto *S = dyn_cast(&Node)) { + if (const auto *S = dyn_cast(EffectiveType)) { return matchesDecl(S->getInterface(), Finder, Builder); } @@ -770,14 +779,14 @@ // template struct X { T t; } class A {}; X a; // The following matcher will match, which otherwise would not: // fieldDecl(hasType(pointerType())). - if (const auto *S = dyn_cast(&Node)) { + if (const auto *S = dyn_cast(EffectiveType)) { return matchesSpecialized(S->getReplacementType(), Finder, Builder); } // For template specialization types, we want to match the template // declaration, as long as the type is still dependent, and otherwise the // declaration of the instantiated tag type. - if (const auto *S = dyn_cast(&Node)) { + if (const auto *S = dyn_cast(EffectiveType)) { if (!S->isTypeAlias() && S->isSugared()) { // If the template is non-dependent, we want to match the instantiated // tag type. @@ -796,7 +805,7 @@ // FIXME: We desugar elaborated types. This makes the assumption that users // do never want to match on whether a type is elaborated - there are // arguments for both sides; for now, continue desugaring. - if (const auto *S = dyn_cast(&Node)) { + if (const auto *S = dyn_cast(EffectiveType)) { return matchesSpecialized(S->desugar(), Finder, Builder); } return false; Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -1184,6 +1184,10 @@ EXPECT_TRUE(matches("int v[] = { 2, 3 }; void f() { for (int i : v) {} }", autoType())); + EXPECT_TRUE(matches("auto i = 2;", varDecl(hasType(isInteger())))); + EXPECT_TRUE(matches("struct X{}; auto x = X{};", + varDecl(hasType(recordDecl(hasName("X")))))); + // FIXME: Matching against the type-as-written can't work here, because the // type as written was not deduced. //EXPECT_TRUE(matches("auto a = 1;",