diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -7084,7 +7084,8 @@ // functions. In such a case, the candidate functions generated from each // function template are combined with the set of non-template candidate // functions. - TemplateDeductionInfo Info(CandidateSet.getLocation()); + TemplateDeductionInfo Info(CandidateSet.getLocation(), + MethodTmpl->getTemplateParameters()->getDepth()); FunctionDecl *Specialization = nullptr; ConversionSequenceList Conversions; if (TemplateDeductionResult Result = DeduceTemplateArguments( @@ -14171,8 +14172,12 @@ IsError |= InputInit.isInvalid(); Arg = InputInit.getAs(); } else { - ExprResult DefArg = - S.BuildCXXDefaultArgExpr(LParenLoc, Method, Method->getParamDecl(i)); + ParmVarDecl *Param = Method->getParamDecl(i); + if (!Param->hasDefaultArg()) { + IsError = true; + break; + } + ExprResult DefArg = S.BuildCXXDefaultArgExpr(LParenLoc, Method, Param); if (DefArg.isInvalid()) { IsError = true; break; diff --git a/clang/test/CXX/temp/temp.decls/temp.variadic/p5-cxx20.cpp b/clang/test/CXX/temp/temp.decls/temp.variadic/p5-cxx20.cpp new file mode 100644 --- /dev/null +++ b/clang/test/CXX/temp/temp.decls/temp.variadic/p5-cxx20.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s +// expected-no-diagnostics + +namespace pr28087 { +template auto apply(F f) { f(); } +template struct S { + template auto f(decltype(apply([](auto...) {}))); +}; +template struct S<>; +} // namespace pr28087