diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp --- a/clang-tools-extra/clangd/FindTarget.cpp +++ b/clang-tools-extra/clangd/FindTarget.cpp @@ -634,6 +634,17 @@ /*IsDecl=*/false, {E->getPack()}}); } + + void VisitDesignatedInitExpr(const DesignatedInitExpr *DIE) { + for (const DesignatedInitExpr::Designator &D : DIE->designators()) { + if (!D.isFieldDesignator()) + continue; + Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(), + D.getFieldLoc(), + /*IsDecl=*/false, + {D.getField()}}); + } + } }; Visitor V; diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp --- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -563,7 +563,7 @@ // FIXME: Auto-completion in a template requires disabling delayed template // parsing. TU.ExtraArgs.push_back("-fno-delayed-template-parsing"); - TU.ExtraArgs.push_back("-std=c++17"); + TU.ExtraArgs.push_back("-std=c++2a"); auto AST = TU.build(); for (auto &D : AST.getDiagnostics()) { @@ -753,6 +753,20 @@ )cpp", "0: targets = {a}\n" "1: targets = {b}\n"}, + // Designated initializers. + {R"cpp( + void foo() { + struct $0^Foo { + int $1^Bar; + }; + $2^Foo $3^f { .$4^Bar = 42 }; + } + )cpp", + "0: targets = {Foo}, decl\n" + "1: targets = {foo()::Foo::Bar}, decl\n" + "2: targets = {Foo}\n" + "3: targets = {f}, decl\n" + "4: targets = {foo()::Foo::Bar}\n"}, // No references from implicit nodes. {R"cpp( struct vector { @@ -969,7 +983,21 @@ } )cpp", "0: targets = {Test}\n" - "1: targets = {a}, decl\n"}}; + "1: targets = {a}, decl\n"}, + // Designated initializers. + {R"cpp( + void foo() { + struct $0^Foo { + int $1^Bar; + }; + $2^Foo $3^f { .$4^Bar = 42 }; + } + )cpp", + "0: targets = {Foo}, decl\n" + "1: targets = {foo()::Foo::Bar}, decl\n" + "2: targets = {Foo}\n" + "3: targets = {f}, decl\n" + "4: targets = {foo()::Foo::Bar}\n"}}; for (const auto &C : Cases) { llvm::StringRef ExpectedCode = C.first; diff --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp b/clang-tools-extra/clangd/unittests/RenameTests.cpp --- a/clang-tools-extra/clangd/unittests/RenameTests.cpp +++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp @@ -403,6 +403,14 @@ template class Z> struct Bar { }; template <> struct Bar<[[Foo]]> {}; )cpp", + + // Designated initializer. + R"cpp( + struct Bar { + int [[Fo^o]]; + }; + Bar bar { .[[^Foo]]= 42 }; + )cpp", }; for (llvm::StringRef T : Tests) { Annotations Code(T);