Skip to content

Commit

Permalink
[clang] Do not crash when CXXRecordDecl has a non-CXXRecordDecl base.
Browse files Browse the repository at this point in the history
This can happen on some invalid code, like the included test case.

Differential Revision: https://reviews.llvm.org/D94704
  • Loading branch information
gislan committed Jan 14, 2021
1 parent 5cf2696 commit a71877e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5520,8 +5520,9 @@ Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,

// Bases.
for (const auto &Base : ClassDecl->bases()) {
// Bases are always records in a well-formed non-dependent class.
const RecordType *RT = Base.getType()->getAs<RecordType>();
if (!RT)
continue;

// Remember direct virtual bases.
if (Base.isVirtual()) {
Expand Down
14 changes: 14 additions & 0 deletions clang/test/SemaTemplate/temp_class_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,17 @@ namespace PR6181 {
};

}

// Check that we do not crash on invalid code that leads to invalid base.
namespace {
template <typename X>
class Foo {};

template <int Y>
class Bar;

template <typename Z>
class Bar<0> : public Foo<Z> { // expected-error{{partial specialization of 'Bar' does not use any of its template parameters}}
Bar() : Foo<Z>() {}
};
} // namespace

0 comments on commit a71877e

Please sign in to comment.