From bf559a7f3fca4630b3e3511da18ab78d65a5e7ff Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Wed, 29 May 2019 10:11:14 +0000 Subject: [PATCH] [Index] Correctly set symbol kind of IndirectFieldDecl Summary: The kind has been 'unknown' before, now it is 'field'. Reviewers: kadircet Reviewed By: kadircet Subscribers: jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62573 llvm-svn: 361941 --- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp | 14 ++++++++++++++ clang/lib/Index/IndexSymbol.cpp | 1 + clang/test/Index/index-anonymous-union-fields.cpp | 10 ++++++++++ 3 files changed, 25 insertions(+) create mode 100644 clang/test/Index/index-anonymous-union-fields.cpp diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp index a7aa165..b9ca702 100644 --- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -449,6 +449,20 @@ TEST(CompletionTest, Kinds) { 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 index a8f11b3..db397b9 100644 --- a/clang/lib/Index/IndexSymbol.cpp +++ b/clang/lib/Index/IndexSymbol.cpp @@ -168,6 +168,7 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { 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 index 0000000..30f254d --- /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 -- 2.7.4