https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118210

            Bug ID: 118210
           Summary: g++-14.2 fails to parse template lambda expression
                    operator()<>() call inside the requires expression.
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: piotr.rak at gmail dot com
  Target Milestone: ---

Created attachment 59983
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59983&action=edit
Test case

Hello,

g++-14.2 fails to parse template lambda expression template operator()<>() call
inside the requires expression.

Example:

requires{[]<typename T>{}.template operator()<char>();} //error: expected
nested-name-specifier before ‘T’
//error: expected ‘(’ before ‘T’
//error: expected ‘;’ before ‘.’ token

An expression:
[]<typename T>{}.template operator()<char>(); // compiles just fine
Outside the scope requires-expr.

I found this oddity trying to emulate clang __has_constexpr_builtin() invoking
such builtin wrapped in consteval template lambda expression.
As clang __has_constexpr_builtin works sparingly (trait builtin return false)
idea was to check abuse consteval context for both compilers.

As of 14.2 direct lambda calls with template type deduction do work (like
requires {[]<typename T>(T){}(char{});} ).

Please see attached or following example:

// compile -std=c++23 -DSHOW_BUG=1
#if SHOW_BUG
#define requires_expr requires
#else
#define requires_expr
#endif

using any_type_example = char;

void foo1() { requires_expr { []<typename T>(){}.template
operator()<any_type_example>(); }; }
void foo2() { requires_expr { []<typename T>{}.template
operator()<any_type_example>(); }; }
void foo3() { requires_expr { []<int>{}.template operator()<1>(); }; }

Cheers,
/P

Reply via email to