Skip to content

Commit 68920b5

Browse files
authored
Merge pull request #4772 from apple/egorzhdan/rdar93610386_swift57
🍒[clang] Don't crash on an incomplete-type base specifier in template context.
2 parents c4df893 + d7782e4 commit 68920b5

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

clang/lib/AST/DeclCXX.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ static bool hasRepeatedBaseClass(const CXXRecordDecl *StartRD) {
178178
SmallVector<const CXXRecordDecl*, 8> WorkList = {StartRD};
179179
while (!WorkList.empty()) {
180180
const CXXRecordDecl *RD = WorkList.pop_back_val();
181+
if (RD->getTypeForDecl()->isDependentType())
182+
continue;
181183
for (const CXXBaseSpecifier &BaseSpec : RD->bases()) {
182184
if (const CXXRecordDecl *B = BaseSpec.getType()->getAsCXXRecordDecl()) {
183185
if (!SeenBaseTypes.insert(B).second)

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,6 +2729,8 @@ bool Sema::AttachBaseSpecifiers(CXXRecordDecl *Class,
27292729
KnownBase = Bases[idx];
27302730
Bases[NumGoodBases++] = Bases[idx];
27312731

2732+
if (NewBaseType->isDependentType())
2733+
continue;
27322734
// Note this base's direct & indirect bases, if there could be ambiguity.
27332735
if (Bases.size() > 1)
27342736
NoteIndirectBases(Context, IndirectBaseTypes, NewBaseType);
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify %s
2-
// expected-no-diagnostics
32

43
template <typename T> class Foo {
54
struct Base : T {};
65

76
// Test that this code no longer causes a crash in Sema. rdar://23291875
87
struct Derived : Base, T {};
98
};
9+
10+
11+
template <typename T> struct Foo2 {
12+
struct Base1; // expected-note{{member is declared here}}
13+
struct Base2; // expected-note{{member is declared here}}
14+
// Should not crash on an incomplete-type and dependent base specifier.
15+
struct Derived : Base1, Base2 {}; // expected-error {{implicit instantiation of undefined member 'Foo2<int>::Base1'}} \
16+
expected-error {{implicit instantiation of undefined member 'Foo2<int>::Base2'}}
17+
};
18+
19+
Foo2<int>::Derived a; // expected-note{{in instantiation of member class}}

clang/test/SemaCXX/ms-interface.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,10 @@ static_assert(!__is_interface_class(HasProp), "oops");
106106
static_assert(!__is_interface_class(IUnknown), "oops");
107107
static_assert(!__is_interface_class(IFaceStruct), "oops");
108108
static_assert(!__is_interface_class(IFaceInheritsStruct), "oops");
109+
110+
template<typename>
111+
class TemplateContext {
112+
class Base;
113+
// Should not crash on an incomplete-type and dependent base specifier.
114+
__interface Foo : Base {};
115+
};

0 commit comments

Comments
 (0)