[Index] Correctly set symbol kind of IndirectFieldDecl
authorIlya Biryukov <ibiryukov@google.com>
Wed, 29 May 2019 10:11:14 +0000 (10:11 +0000)
committerIlya Biryukov <ibiryukov@google.com>
Wed, 29 May 2019 10:11:14 +0000 (10:11 +0000)
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
clang/lib/Index/IndexSymbol.cpp
clang/test/Index/index-anonymous-union-fields.cpp [new file with mode: 0644]

index a7aa165..b9ca702 100644 (file)
@@ -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) {
index a8f11b3..db397b9 100644 (file)
@@ -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<CXXRecordDecl>(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 (file)
index 0000000..30f254d
--- /dev/null
@@ -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