[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 12:28:14 PST 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa71877edfbb7: [clang] Do not crash when CXXRecordDecl has a non-CXXRecordDecl base. (authored by adamcz).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94704/new/

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.316744.patch
Type: text/x-patch
Size: 1105 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210114/e0d2c024/attachment.bin>


More information about the cfe-commits mailing list