[gcc r15-10658] c++: Allow lambda expressions in template type parameters [PR116952]

Jason Merrill jason@gcc.gnu.org
Fri Jan 9 07:03:51 GMT 2026


https://gcc.gnu.org/g:66fe4ac0fa6efaa7213d6c6afd9e7ea77688e072

commit r15-10658-g66fe4ac0fa6efaa7213d6c6afd9e7ea77688e072
Author: Eczbek <eczbek.void@gmail.com>
Date:   Fri Jan 9 15:02:53 2026 +0800

    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 <jason@redhat.com>
    (cherry picked from commit ef4cd115ef67736b2af06fb7b47410961b73e7d6)

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 c208e3862e71..2839e80f06a2 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -11693,21 +11693,7 @@ cp_parser_lambda_expression (cp_parser* parser)
   LAMBDA_EXPR_LOCATION (lambda_expr) = token->location;
 
   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;


More information about the Gcc-cvs mailing list