]> granicus.if.org Git - clang/commitdiff
[Sema] Fix crash for type-dependent base classes
authorJan Korous <jkorous@apple.com>
Sat, 13 Jan 2018 15:24:16 +0000 (15:24 +0000)
committerJan Korous <jkorous@apple.com>
Sat, 13 Jan 2018 15:24:16 +0000 (15:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@322438 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/base-class-ambiguity-check.cpp [new file with mode: 0644]

index f0a176b14cff79f8021bd1dade60fefc859414e7..6873feb7802bdd57609b9fd1d3ad699abe63c458 100644 (file)
@@ -2417,9 +2417,16 @@ bool Sema::AttachBaseSpecifiers(CXXRecordDecl *Class,
   // 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 the base specifier is a CXXRecord.
+    if (BaseType->isDependentType())
+      continue;
+
     CanQualType CanonicalBase = Context.getCanonicalType(BaseType)
       .getUnqualifiedType();
 
diff --git a/test/SemaCXX/base-class-ambiguity-check.cpp b/test/SemaCXX/base-class-ambiguity-check.cpp
new file mode 100644 (file)
index 0000000..fc1c4c2
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template <typename T> class Foo {
+  struct Base : T {};
+
+  // Test that this code no longer causes a crash in Sema. rdar://23291875
+  struct Derived : Base, T {};
+};