diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -4189,6 +4189,9 @@ for (unsigned OldIdx = 0, NumOldParams = OldProtoLoc.getNumParams(); OldIdx != NumOldParams; ++OldIdx) { ParmVarDecl *OldParam = OldProtoLoc.getParam(OldIdx); + if (!OldParam) + return nullptr; + LocalInstantiationScope *Scope = SemaRef.CurrentInstantiationScope; Optional NumArgumentsInExpansion; diff --git a/clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp b/clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp @@ -0,0 +1,13 @@ +// RUN: %clang -fsyntax-only -std=c++17 %s -Xclang -verify +#include + +template +auto Call(T x) -> typename std::result_of::type {} // expected-note{{candidate template ignored}} + +class Status {}; + +void fun() { + // The Status() (instead of Status) here used to cause a crash. + Call([](auto x) -> Status() {}); // expected-error{{function cannot return function type 'Status ()}} + // expected-error@-1{{no matching function for call to 'Call'}} +}