Index: include/clang/AST/RecursiveASTVisitor.h =================================================================== --- include/clang/AST/RecursiveASTVisitor.h +++ include/clang/AST/RecursiveASTVisitor.h @@ -809,6 +809,10 @@ if (Init->isWritten() || getDerived().shouldVisitImplicitCode()) TRY_TO(TraverseStmt(Init->getInit())); + + if (Init->getNumArrayIndices() && getDerived().shouldVisitImplicitCode()) + for (VarDecl *VD : Init->getArrayIndexes()) + TRY_TO(TraverseDecl(VD)); return true; } Index: unittests/ASTMatchers/ASTMatchersTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersTest.cpp +++ unittests/ASTMatchers/ASTMatchersTest.cpp @@ -4207,6 +4207,14 @@ hasAncestor(cxxRecordDecl(unless(isTemplateInstantiation()))))))); } +TEST(HasAncestor, ImplicitArrayCopyCtorDeclRefExpr) { + EXPECT_TRUE(matches("struct MyClass {\n" + " int c[1];\n" + " static MyClass Create() { return MyClass(); }\n" + "};", + declRefExpr(to(decl(hasAncestor(decl())))))); +} + TEST(HasParent, MatchesAllParents) { EXPECT_TRUE(matches( "template struct C { static void f() { 42; } };"