[PATCH] D113474: [clang] Don't crash on an incomplete-type base specifier in template context.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 9 07:08:31 PST 2021


hokein updated this revision to Diff 385807.
hokein marked 2 inline comments as done.
hokein added a comment.

address comments and added a missing case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113474

Files:
  clang/lib/AST/DeclCXX.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/base-class-ambiguity-check.cpp
  clang/test/SemaCXX/ms-interface.cpp


Index: clang/test/SemaCXX/ms-interface.cpp
===================================================================
--- clang/test/SemaCXX/ms-interface.cpp
+++ clang/test/SemaCXX/ms-interface.cpp
@@ -106,3 +106,10 @@
 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 {};
+};
Index: clang/test/SemaCXX/base-class-ambiguity-check.cpp
===================================================================
--- clang/test/SemaCXX/base-class-ambiguity-check.cpp
+++ clang/test/SemaCXX/base-class-ambiguity-check.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 template <typename T> class Foo {
   struct Base : T {};
@@ -7,3 +6,14 @@
   // 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}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -2729,6 +2729,8 @@
       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);
Index: clang/lib/AST/DeclCXX.cpp
===================================================================
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -178,6 +178,8 @@
   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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113474.385807.patch
Type: text/x-patch
Size: 2741 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211109/b049514c/attachment-0001.bin>


More information about the cfe-commits mailing list