diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 3ae2822a9803..b37b4bbba783 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::foo1('a', 1, 2, 3, 4)); // expected-error{{no matching function}} using gf2 = decltype(G::foo2('a', 1, 2)); // expected-error{{no matching function}} + + +// Regression (bug #45102): check that instantiation works where there is no +// TemplateTypeParmDecl +template using id = T; + +template +constexpr void g() { + id f; +} + +static_assert((g(), true)); \ No newline at end of file