[PATCH] D94704: [clang] Do not crash when CXXRecordDecl has a non-CXXRecordDecl base.
Adam Czachorowski via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 14 11:58:04 PST 2021
adamcz created this revision.
adamcz added a reviewer: hokein.
adamcz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This can happen on some invalid code, like the included test case.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D94704
Files:
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaTemplate/temp_class_spec.cpp
Index: clang/test/SemaTemplate/temp_class_spec.cpp
===================================================================
--- clang/test/SemaTemplate/temp_class_spec.cpp
+++ clang/test/SemaTemplate/temp_class_spec.cpp
@@ -361,3 +361,17 @@
};
}
+
+// 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
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -5520,8 +5520,9 @@
// 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()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94704.316729.patch
Type: text/x-patch
Size: 1105 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210114/e67626cb/attachment.bin>
More information about the cfe-commits
mailing list