jkorous-apple created this revision.
jkorous-apple added a reviewer: arphaman.

The original code is checking for inaccessible base classes but does not expect 
inheriting from template parameters (or dependent types in general) as these 
are not modelled by CXXRecord.

Issue was at this line since getAsCXXRecord() returned nullptr:

  bool found
          = Class->isDerivedFrom(CanonicalBase->getAsCXXRecordDecl(), Paths);


https://reviews.llvm.org/D41897

Files:
  Sema/SemaDeclCXX.cpp
  SemaCXX/base-class-ambiguity-check.cpp


Index: SemaCXX/base-class-ambiguity-check.cpp
===================================================================
--- /dev/null
+++ SemaCXX/base-class-ambiguity-check.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only %s
+
+template<typename T>
+class Foo
+{
+        struct Base : T
+        { };
+
+        struct Derived : Base, T
+        { };
+};
\ No newline at end of file
Index: Sema/SemaDeclCXX.cpp
===================================================================
--- Sema/SemaDeclCXX.cpp
+++ Sema/SemaDeclCXX.cpp
@@ -2417,9 +2417,17 @@
   // Attach the remaining base class specifiers to the derived class.
   Class->setBases(Bases.data(), NumGoodBases);
 
+  // Check that the only base classes that are duplicate are virtual.
   for (unsigned idx = 0; idx < NumGoodBases; ++idx) {
     // Check whether this direct base is inaccessible due to ambiguity.
     QualType BaseType = Bases[idx]->getType();
+
+    // Skip all dependent types in templates being used as base specifiers.
+    // Checks below assume that base specifier is a CXXRecord.
+    if (BaseType->isDependentType()) {
+      continue;
+    }
+
     CanQualType CanonicalBase = Context.getCanonicalType(BaseType)
       .getUnqualifiedType();
 


Index: SemaCXX/base-class-ambiguity-check.cpp
===================================================================
--- /dev/null
+++ SemaCXX/base-class-ambiguity-check.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only %s
+
+template<typename T>
+class Foo
+{
+        struct Base : T
+        { };
+
+        struct Derived : Base, T
+        { };
+};
\ No newline at end of file
Index: Sema/SemaDeclCXX.cpp
===================================================================
--- Sema/SemaDeclCXX.cpp
+++ Sema/SemaDeclCXX.cpp
@@ -2417,9 +2417,17 @@
   // Attach the remaining base class specifiers to the derived class.
   Class->setBases(Bases.data(), NumGoodBases);
 
+  // Check that the only base classes that are duplicate are virtual.
   for (unsigned idx = 0; idx < NumGoodBases; ++idx) {
     // Check whether this direct base is inaccessible due to ambiguity.
     QualType BaseType = Bases[idx]->getType();
+
+    // Skip all dependent types in templates being used as base specifiers.
+    // Checks below assume that base specifier is a CXXRecord.
+    if (BaseType->isDependentType()) {
+      continue;
+    }
+
     CanQualType CanonicalBase = Context.getCanonicalType(BaseType)
       .getUnqualifiedType();
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to