template <auto> void f() { } constexpr auto g = f<[] (int x, int y) { return x > y; }>; This produces the following diagnostic: <source>: In lambda function: <source>:5:50: error: expected ';' before '>' token 5 | constexpr auto g = f<[] (int x, int y) { return x > y; }>; | ^~ | ; <source>:5:51: error: expected primary-expression before '>' token 5 | constexpr auto g = f<[] (int x, int y) { return x > y; }>; | ^ ASM generation compiler returned: 1 <source>: In lambda function: <source>:5:50: error: expected ';' before '>' token 5 | constexpr auto g = f<[] (int x, int y) { return x > y; }>; | ^~ | ; <source>:5:51: error: expected primary-expression before '>' token 5 | constexpr auto g = f<[] (int x, int y) { return x > y; }>; | ^ Godbolt link to the above: https://godbolt.org/z/KG6d5E6ev Changing the body to return (x > y); makes the error go away as a workaround. So I speculate that the greater-than operator is misparsed as the end of the template argument list.
I suspect this is the same issue as PR 57 .
Even template defaults has issues: template <auto = [] (int x, int y) { return x > y; }> int t = 0; Which is why I Pointed to PR 57.
I wonder if this is still an ambiguous part of the C++ grammar and all.
It seems that the core of PR 57 is that `A<T` could syntactically be a valid expression, and it would require a look-up to determine that A and T are in fact a template and a type, and not values. Here, however, the fragment `[] (int x, int y) { return x` doesn't form a syntactically valid expression. So, to me at least, it seems there should be no ambiguity.
template<auto F> struct Foo {}; Foo<[](){ return 1 >= 0; }> foo1{}; Foo<[](){ return (1 > 0); }> foo2{}; Foo<[](){ return 1 > 0; }> foo3{}; I ran afoul of this bug, and found this issue. Can confirm that this bug is still present in GCC 15.1.0. GCC accepts foo1 and foo2, but rejects foo3. Clang does accept all 3.
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:00e8690ef0d7ac1ced87ceee309dbfa27909a35c commit r16-3444-g00e8690ef0d7ac1ced87ceee309dbfa27909a35c Author: Jason Merrill <jason@redhat.com> Date: Sun Aug 24 05:15:01 2025 -0400 c++: > in lambda in template arg [PR107953] As with PR116928, we need to set greater_than_is_operator_p within the lambda delimiters. PR c++/107953 gcc/cp/ChangeLog: * parser.cc (cp_parser_lambda_expression): Set greater_than_is_operator_p. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/lambda-targ18.C: New test.
Fixed for GCC 16.