Skip to content

Commit 00f34ee

Browse files
authored
[clang] Bail out if the result of function template instantiation is not a function type. (#69459)
1 parent dc27d21 commit 00f34ee

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2662,7 +2662,9 @@ TypeSourceInfo *Sema::SubstFunctionDeclType(TypeSourceInfo *T,
26622662
} else {
26632663
Result = Instantiator.TransformType(TLB, TL);
26642664
}
2665-
if (Result.isNull())
2665+
// When there are errors resolving types, clang may use IntTy as a fallback,
2666+
// breaking our assumption that function declarations have function types.
2667+
if (Result.isNull() || !Result->isFunctionType())
26662668
return nullptr;
26672669

26682670
return TLB.getTypeSourceInfo(Context, Result);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -x c++ -std=c++14 -fsyntax-only -verify %s
2+
3+
template <class A>
4+
using Type = typename A::NestedType; // expected-error {{type 'float' cannot be used prior to '::' because it has no members}}
5+
6+
template <typename T>
7+
void Func() {
8+
using MyType = Type<T>(); // expected-note {{in instantiation of template type alias 'Type' requested here}}
9+
// This is a function declaration, not a variable declaration!
10+
// After substitution, we do not have a valid function type, and used to crash.
11+
MyType var;
12+
}
13+
14+
void Test() {
15+
Func<float>(); // expected-note {{in instantiation of function template specialization 'Func<float>' requested here}}
16+
}

0 commit comments

Comments
 (0)