https://gcc.gnu.org/g:ef4cd115ef67736b2af06fb7b47410961b73e7d6

commit r16-5726-gef4cd115ef67736b2af06fb7b47410961b73e7d6
Author: Eczbek <[email protected]>
Date:   Tue Nov 25 00:26:50 2025 -0500

    c++: Allow lambda expressions in template type parameters [PR116952]
    
            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 <[email protected]>

Diff:
---
 gcc/cp/parser.cc                             | 16 +---------------
 gcc/testsuite/g++.dg/cpp2a/lambda-uneval14.C |  4 ++--
 gcc/testsuite/g++.dg/cpp2a/lambda-uneval29.C |  5 +++++
 3 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index e0c8e0ec8ad2..de11798b8bdc 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -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)
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-uneval14.C 
b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval14.C
index a18035954e16..d0e74e3c8057 100644
--- a/gcc/testsuite/g++.dg/cpp2a/lambda-uneval14.C
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval14.C
@@ -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
index 000000000000..76e743fedcef
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval29.C
@@ -0,0 +1,5 @@
+// PR c++/116952
+// { dg-do compile { target c++20 } }
+
+template<typename, auto> concept A = true;
+template<A<[] {}>> int x;

Reply via email to