Skip to content

🍒[clang] Don't crash on an incomplete-type base specifier in template context. #4772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/lib/AST/DeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ static bool hasRepeatedBaseClass(const CXXRecordDecl *StartRD) {
SmallVector<const CXXRecordDecl*, 8> WorkList = {StartRD};
while (!WorkList.empty()) {
const CXXRecordDecl *RD = WorkList.pop_back_val();
if (RD->getTypeForDecl()->isDependentType())
continue;
for (const CXXBaseSpecifier &BaseSpec : RD->bases()) {
if (const CXXRecordDecl *B = BaseSpec.getType()->getAsCXXRecordDecl()) {
if (!SeenBaseTypes.insert(B).second)
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2729,6 +2729,8 @@ bool Sema::AttachBaseSpecifiers(CXXRecordDecl *Class,
KnownBase = Bases[idx];
Bases[NumGoodBases++] = Bases[idx];

if (NewBaseType->isDependentType())
continue;
// Note this base's direct & indirect bases, if there could be ambiguity.
if (Bases.size() > 1)
NoteIndirectBases(Context, IndirectBaseTypes, NewBaseType);
Expand Down
12 changes: 11 additions & 1 deletion clang/test/SemaCXX/base-class-ambiguity-check.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics

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

// Test that this code no longer causes a crash in Sema. rdar://23291875
struct Derived : Base, T {};
};


template <typename T> struct Foo2 {
struct Base1; // expected-note{{member is declared here}}
struct Base2; // expected-note{{member is declared here}}
// Should not crash on an incomplete-type and dependent base specifier.
struct Derived : Base1, Base2 {}; // expected-error {{implicit instantiation of undefined member 'Foo2<int>::Base1'}} \
expected-error {{implicit instantiation of undefined member 'Foo2<int>::Base2'}}
};

Foo2<int>::Derived a; // expected-note{{in instantiation of member class}}
7 changes: 7 additions & 0 deletions clang/test/SemaCXX/ms-interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,10 @@ static_assert(!__is_interface_class(HasProp), "oops");
static_assert(!__is_interface_class(IUnknown), "oops");
static_assert(!__is_interface_class(IFaceStruct), "oops");
static_assert(!__is_interface_class(IFaceInheritsStruct), "oops");

template<typename>
class TemplateContext {
class Base;
// Should not crash on an incomplete-type and dependent base specifier.
__interface Foo : Base {};
};