diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp --- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -449,6 +449,20 @@ Results = completions("nam^"); EXPECT_THAT(Results.Completions, Has("namespace", CompletionItemKind::Snippet)); + + // Members of anonymous unions are of kind 'field'. + Results = completions( + R"cpp( + struct X{ + union { + void *a; + }; + }; + auto u = X().^ + )cpp"); + EXPECT_THAT( + Results.Completions, + UnorderedElementsAre(AllOf(Named("a"), Kind(CompletionItemKind::Field)))); } TEST(CompletionTest, NoDuplicates) { diff --git a/clang/lib/Index/IndexSymbol.cpp b/clang/lib/Index/IndexSymbol.cpp --- a/clang/lib/Index/IndexSymbol.cpp +++ b/clang/lib/Index/IndexSymbol.cpp @@ -168,6 +168,7 @@ Info.Kind = SymbolKind::Function; break; case Decl::Field: + case Decl::IndirectField: Info.Kind = SymbolKind::Field; if (const CXXRecordDecl * CXXRec = dyn_cast(D->getDeclContext())) { diff --git a/clang/test/Index/index-anonymous-union-fields.cpp b/clang/test/Index/index-anonymous-union-fields.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Index/index-anonymous-union-fields.cpp @@ -0,0 +1,10 @@ +struct X { + union { + void *a; + }; +}; + +// RUN: c-index-test -index-file %s > %t +// RUN: FileCheck %s -input-file=%t + +// CHECK: [indexDeclaration]: kind: field | name: a | {{.*}} | loc: 3:11