[llvm-branch-commits] [clang] 7c18c2f - [Concepts] Add null check for TemplateTypeParmType::getDecl() in GetContainedInventedTypeParmVisitor

Saar Raz via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Mar 6 09:35:09 PST 2020


Author: Saar Raz
Date: 2020-03-06T19:34:43+02:00
New Revision: 7c18c2f709e9a1009c120ff31863799a1279c3b1

URL: https://github.com/llvm/llvm-project/commit/7c18c2f709e9a1009c120ff31863799a1279c3b1
DIFF: https://github.com/llvm/llvm-project/commit/7c18c2f709e9a1009c120ff31863799a1279c3b1.diff

LOG: [Concepts] Add null check for TemplateTypeParmType::getDecl() in GetContainedInventedTypeParmVisitor

GetContainedInventedTypeParmVisitor would not account for the case where TemplateTypeParmType::getDecl() is
nullptr, causing bug #45102.

Add the nullptr check.

(cherry picked from commit 865456d589e093582acaafd17d58ad1c0cce66af)

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 568f5404dc0b..ce9a0263bd50 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -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();
     }

diff  --git a/clang/test/SemaTemplate/instantiate-abbreviated-template.cpp b/clang/test/SemaTemplate/instantiate-abbreviated-template.cpp
index 99801115626f..1f2171a25ebb 100644
--- a/clang/test/SemaTemplate/instantiate-abbreviated-template.cpp
+++ b/clang/test/SemaTemplate/instantiate-abbreviated-template.cpp
@@ -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


        


More information about the llvm-branch-commits mailing list