Skip to content

Commit 852bf47

Browse files
fix: Fix crash when emitting relationships (#394)
When looking up base classes, we need to check if the definition exists, as it may not for templated classes.
1 parent 17a37d9 commit 852bf47

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

indexer/Indexer.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ void TuIndexer::saveTagDecl(const clang::TagDecl &tagDecl) {
735735
continue;
736736
}
737737
if (seen.find(cxxRecordDecl) == seen.end()) {
738-
// See FIXME(ref: template-specialization-support) When we get the decl
738+
// FIXME(def: template-specialization-support) When we get the decl
739739
// symbol here, we need to handle different kinds of templates
740740
// differently. E.g. in the ImplicitInstantiation case, call
741741
// getTemplateInstantiationPattern and use that rather than using the
@@ -750,7 +750,12 @@ void TuIndexer::saveTagDecl(const clang::TagDecl &tagDecl) {
750750
}
751751
seen.insert(cxxRecordDecl);
752752
}
753-
753+
if (!cxxRecordDecl->hasDefinition()) {
754+
// FIXME(def: template-specialization-support) This case
755+
// can be hit when inheriting from an explicit specialization
756+
// for which the unspecialized record lacks a definition.
757+
continue;
758+
}
754759
for (const clang::CXXBaseSpecifier &cxxBaseSpecifier :
755760
cxxRecordDecl->bases()) {
756761
auto baseType = cxxBaseSpecifier.getType().getCanonicalType();

test/index/types/inheritance.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// extra-args: -std=c++17
2+
13
struct MonoBase {};
24

35
struct MonoDerived: MonoBase {};
@@ -35,4 +37,12 @@ template <typename T>
3537
struct DerivedFromTemplateParam: T {};
3638

3739
template <template <typename> typename H>
38-
struct DerivedFromTemplateTemplateParam: H<int> {};
40+
struct DerivedFromTemplateTemplateParam: H<int> {};
41+
42+
template <bool, class T> struct BaseWithOnlySpecializations;
43+
44+
template <class T>
45+
struct BaseWithOnlySpecializations<false, T> {};
46+
47+
template <class T>
48+
struct DerivedFromBasedWithOnlySpecialization: public BaseWithOnlySpecializations<false, T> {};

test/index/types/inheritance.snapshot.cc

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
// extra-args: -std=c++17
2+
//^^^^^^^^^^^^^^^^^^^^^^^^^ definition [..] `<file>/inheritance.cc`/
3+
14
struct MonoBase {};
2-
//^^^^^^ definition [..] `<file>/inheritance.cc`/
35
// ^^^^^^^^ definition [..] MonoBase#
46

57
struct MonoDerived: MonoBase {};
@@ -87,3 +89,21 @@
8789
struct DerivedFromTemplateTemplateParam: H<int> {};
8890
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition [..] DerivedFromTemplateTemplateParam#
8991
// ^ reference local 7
92+
93+
template <bool, class T> struct BaseWithOnlySpecializations;
94+
// ^ definition local 8
95+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] BaseWithOnlySpecializations#
96+
97+
template <class T>
98+
// ^ definition local 9
99+
struct BaseWithOnlySpecializations<false, T> {};
100+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition [..] BaseWithOnlySpecializations#
101+
// ^ reference local 9
102+
103+
template <class T>
104+
// ^ definition local 10
105+
struct DerivedFromBasedWithOnlySpecialization: public BaseWithOnlySpecializations<false, T> {};
106+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition [..] DerivedFromBasedWithOnlySpecialization#
107+
// relation implementation [..] BaseWithOnlySpecializations#
108+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ reference [..] BaseWithOnlySpecializations#
109+
// ^ reference local 10

0 commit comments

Comments
 (0)