[Concepts] Add null check for TemplateTypeParmType::getDecl() in GetContainedInvented...
authorSaar Raz <saar@raz.email>
Fri, 6 Mar 2020 16:45:12 +0000 (18:45 +0200)
committerSaar Raz <saar@raz.email>
Fri, 6 Mar 2020 17:32:10 +0000 (19:32 +0200)
GetContainedInventedTypeParmVisitor would not account for the case where TemplateTypeParmType::getDecl() is
nullptr, causing bug #45102.

Add the nullptr check.

clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/SemaTemplate/instantiate-abbreviated-template.cpp

index 3ae2822..b37b4bb 100644 (file)
@@ -2162,7 +2162,7 @@ namespace {
     // The deduced type itself.
     TemplateTypeParmDecl *VisitTemplateTypeParmType(
         const TemplateTypeParmType *T) {
-      if (!T->getDecl()->isImplicit())
+      if (!T->getDecl() || !T->getDecl()->isImplicit())
         return nullptr;
       return T->getDecl();
     }
index 9980111..1f2171a 100644 (file)
@@ -31,3 +31,15 @@ struct G {
 
 using gf1 = decltype(G<int, char>::foo1('a', 1, 2, 3, 4)); // expected-error{{no matching function}}
 using gf2 = decltype(G<int, char>::foo2('a', 1, 2)); // expected-error{{no matching function}}
+
+
+// Regression (bug #45102): check that instantiation works where there is no
+// TemplateTypeParmDecl
+template <typename T> using id = T;
+
+template <typename T>
+constexpr void g() {
+  id<void (T)> f;
+}
+
+static_assert((g<int>(), true));
\ No newline at end of file