Skip to content

Commit 7c18c2f

Browse files
committed
[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 865456d)
1 parent edcd83a commit 7c18c2f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2162,7 +2162,7 @@ namespace {
21622162
// The deduced type itself.
21632163
TemplateTypeParmDecl *VisitTemplateTypeParmType(
21642164
const TemplateTypeParmType *T) {
2165-
if (!T->getDecl()->isImplicit())
2165+
if (!T->getDecl() || !T->getDecl()->isImplicit())
21662166
return nullptr;
21672167
return T->getDecl();
21682168
}

clang/test/SemaTemplate/instantiate-abbreviated-template.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,15 @@ struct G {
3131

3232
using gf1 = decltype(G<int, char>::foo1('a', 1, 2, 3, 4)); // expected-error{{no matching function}}
3333
using gf2 = decltype(G<int, char>::foo2('a', 1, 2)); // expected-error{{no matching function}}
34+
35+
36+
// Regression (bug #45102): check that instantiation works where there is no
37+
// TemplateTypeParmDecl
38+
template <typename T> using id = T;
39+
40+
template <typename T>
41+
constexpr void g() {
42+
id<void (T)> f;
43+
}
44+
45+
static_assert((g<int>(), true));

0 commit comments

Comments
 (0)