diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -1553,6 +1553,10 @@ CXXRD = CTSD->getSpecializedTemplate()->getTemplatedDecl(); } + // Can't query bases without a definition. + if (!CXXRD->hasDefinition()) + return Result; + for (auto Base : CXXRD->bases()) { const CXXRecordDecl *ParentDecl = nullptr; diff --git a/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp b/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp --- a/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp +++ b/clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp @@ -30,6 +30,7 @@ using ::testing::AllOf; using ::testing::ElementsAre; using ::testing::Field; +using ::testing::IsEmpty; using ::testing::Matcher; using ::testing::UnorderedElementsAre; @@ -318,6 +319,18 @@ EXPECT_THAT(typeParents(Child3), ElementsAre()); } +TEST(TypeParents, IncompleteClass) { + Annotations Source(R"cpp( + class Incomplete; + )cpp"); + TestTU TU = TestTU::withCode(Source.code()); + auto AST = TU.build(); + + const CXXRecordDecl *Incomplete = + dyn_cast(&findDecl(AST, "Incomplete")); + EXPECT_THAT(typeParents(Incomplete), IsEmpty()); +} + // Parts of getTypeHierarchy() are tested in more detail by the // FindRecordTypeAt.* and TypeParents.* tests above. This test exercises the // entire operation.