diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp index 07a94f30c883..01cf559d7057 100644 --- a/clang/lib/Index/IndexBody.cpp +++ b/clang/lib/Index/IndexBody.cpp @@ -414,7 +414,7 @@ public: auto visitSyntacticDesignatedInitExpr = [&](DesignatedInitExpr *E) -> bool { for (DesignatedInitExpr::Designator &D : llvm::reverse(E->designators())) { - if (D.isFieldDesignator()) + if (D.isFieldDesignator() && D.getField()) return IndexCtx.handleReference(D.getField(), D.getFieldLoc(), Parent, ParentDC, SymbolRoleSet(), {}, E); diff --git a/clang/test/Index/index-designated-init-recovery.cpp b/clang/test/Index/index-designated-init-recovery.cpp new file mode 100644 index 000000000000..182a1aeeb8e6 --- /dev/null +++ b/clang/test/Index/index-designated-init-recovery.cpp @@ -0,0 +1,8 @@ +struct Bar {}; +struct Foo { + void method(Bar bar) {} +}; +void NoCrash(Foo t) { + t.method({.abc = 50}); // CHECK: field designator 'abc' does not refer to any field in type 'Bar' +} +// RUN: c-index-test -index-file %s -Xclang -frecovery-ast 2>&1 | FileCheck %s