[PATCH] D78760: Check a class doesn't have a dependent type before iterating over its base classes

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 19 12:37:09 PDT 2020


ahatanak updated this revision to Diff 264992.
ahatanak retitled this revision from "Check a class has a definition before iterating over its base classes" to "Check a class doesn't have a dependent type before iterating over its base classes".
ahatanak edited the summary of this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78760

Files:
  clang/lib/AST/DeclCXX.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/class.cpp


Index: clang/test/SemaCXX/class.cpp
===================================================================
--- clang/test/SemaCXX/class.cpp
+++ clang/test/SemaCXX/class.cpp
@@ -211,3 +211,30 @@
 struct PR9989 { 
   static int const PR9989_Member = sizeof PR9989_Member; 
 };
+
+namespace dependent_base_type {
+struct B1 {};
+
+template <class T>
+struct S0 {
+  void m0() {
+    struct B0; // expected-note {{member is declared here}}
+
+    struct D : B0, B1 { // expected-error {{implicit instantiation}} expected-note {{in instantiation of}}
+    };
+  }
+};
+
+void test() {
+  S0<int>().m0(); // expected-note {{in instantiation of}}
+}
+
+// clang used to crash compiling this code.
+struct A {};
+template <typename T>
+struct X {
+  struct B : A {};
+  struct C : A, B {};
+};
+
+} // namespace dependent_base_type
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -2611,6 +2611,9 @@
   if (auto Rec = Type->getAs<RecordType>()) {
     auto Decl = Rec->getAsCXXRecordDecl();
 
+    if (Decl->isDependentType())
+      return;
+
     // Iterate over its bases.
     for (const auto &BaseSpec : Decl->bases()) {
       QualType Base = Context.getCanonicalType(BaseSpec.getType())
Index: clang/lib/AST/DeclCXX.cpp
===================================================================
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -173,6 +173,8 @@
   SmallVector<const CXXRecordDecl*, 8> WorkList = {StartRD};
   while (!WorkList.empty()) {
     const CXXRecordDecl *RD = WorkList.pop_back_val();
+    if (RD->isDependentType())
+      continue;
     for (const CXXBaseSpecifier &BaseSpec : RD->bases()) {
       if (const CXXRecordDecl *B = BaseSpec.getType()->getAsCXXRecordDecl()) {
         if (!SeenBaseTypes.insert(B).second)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78760.264992.patch
Type: text/x-patch
Size: 1878 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200519/349360c4/attachment-0001.bin>


More information about the cfe-commits mailing list