Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clang/lib/Sema/SemaTemplateInstantiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions clang/test/SemaTemplate/function-decl-nested-type-alias.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %clang_cc1 -x c++ -std=c++14 -fsyntax-only -verify %s

template <class A>
using Type = typename A::NestedType; // expected-error {{type 'float' cannot be used prior to '::' because it has no members}}

template <typename T>
void Func() {
using MyType = Type<T>(); // 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<float>(); // expected-note {{in instantiation of function template specialization 'Func<float>' requested here}}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Files should have newlines at the end.