]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Allow lambda expressions in template type parameters [PR116952]
authorEczbek <eczbek.void@gmail.com>
Tue, 25 Nov 2025 05:26:50 +0000 (00:26 -0500)
committerJason Merrill <jason@redhat.com>
Sat, 29 Nov 2025 17:36:05 +0000 (23:06 +0530)
PR c++/116952

gcc/cp/ChangeLog:

* parser.cc (cp_parser_lambda_expression): Revert
r11-8166-ge1666ebd9ad31d change prohibiting lambda in non-type
parameter.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/lambda-uneval14.C: Revise incorrect test.
* g++.dg/cpp2a/lambda-uneval29.C: New test.

Co-authored-by: Jason Merrill <jason@redhat.com>
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp2a/lambda-uneval14.C
gcc/testsuite/g++.dg/cpp2a/lambda-uneval29.C [new file with mode: 0644]

index e0c8e0ec8ad260a6a7cf99ebd03e828a44a8978b..de11798b8bdc1d2309753f51ed932ee468b821f0 100644 (file)
@@ -11964,21 +11964,7 @@ cp_parser_lambda_expression (cp_parser* parser,
   LAMBDA_EXPR_CONSTEVAL_BLOCK_P (lambda_expr) = consteval_block_p;
 
   if (cxx_dialect >= cxx20)
-    {
-      /* 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;
-       }
-    }
+    /* C++20 allows lambdas in unevaluated context.  */;
   else if (cp_unevaluated_operand)
     {
       if (!token->error_reported)
index a18035954e16c3f50cdc1f805c4300c0f6ccfe97..d0e74e3c8057c232cd3394a4ed880a2a077de58e 100644 (file)
@@ -1,6 +1,6 @@
 // PR c++/99478
 // { dg-do compile { target c++20 } }
 
-template <decltype ([] {})> auto f() {} // { dg-error "lambda" }
+template <decltype ([] {})> auto f() {}
 
-int main() { f<{}>(); }                // { dg-prune-output "no match" }
+int main() { f<{}>(); }
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-uneval29.C b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval29.C
new file mode 100644 (file)
index 0000000..76e743f
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/116952
+// { dg-do compile { target c++20 } }
+
+template<typename, auto> concept A = true;
+template<A<[] {}>> int x;