diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 23de64080a070..d7d5ce19b75a9 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -2662,7 +2662,9 @@ TypeSourceInfo *Sema::SubstFunctionDeclType(TypeSourceInfo *T, } else { Result = Instantiator.TransformType(TLB, TL); } - if (Result.isNull()) + // When there are errors resolving types, clang may use IntTy as a fallback, + // breaking our assumption that function declarations have function types. + if (Result.isNull() || !Result->isFunctionType()) return nullptr; return TLB.getTypeSourceInfo(Context, Result); diff --git a/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp new file mode 100644 index 0000000000000..4bca990f69046 --- /dev/null +++ b/clang/test/SemaTemplate/function-decl-nested-type-alias.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -x c++ -std=c++14 -fsyntax-only -verify %s + +template +using Type = typename A::NestedType; // expected-error {{type 'float' cannot be used prior to '::' because it has no members}} + +template +void Func() { + using MyType = Type(); // expected-note {{in instantiation of template type alias 'Type' requested here}} + // This is a function declaration, not a variable declaration! + // After substitution, we do not have a valid function type, and used to crash. + MyType var; +} + +void Test() { + Func(); // expected-note {{in instantiation of function template specialization 'Func' requested here}} +} \ No newline at end of file