LAMBDA_EXPR_LOCATION (lambda_expr) = token->location;
if (cxx_dialect >= cxx20)
- /* C++20 allows lambdas in unevaluated context. */;
+ {
+ /* C++20 allows lambdas in unevaluated context, but one in the type of a
+ non-type parameter is nonsensical.
+
+ Distinguish a lambda in the parameter type from a lambda in the
+ default argument by looking at local_variables_forbidden_p, which is
+ only set in default arguments. */
+ if (processing_template_parmlist && !parser->local_variables_forbidden_p)
+ {
+ error_at (token->location,
+ "lambda-expression in template parameter type");
+ token->error_reported = true;
+ ok = false;
+ }
+ }
else if (cp_unevaluated_operand)
{
if (!token->error_reported)
--- /dev/null
+// PR c++/99478
+// { dg-do compile { target c++20 } }
+
+template <decltype ([] {})> auto f() {} // { dg-error "lambda" }
+
+int main() { f<{}>(); } // { dg-prune-output "no match" }