拒绝 lambda 表达式

303*_*303 6 c++ language-lawyer c++20

以下 lambda 表达式似乎被 Clang 和 MSVC 拒绝,而 GCC 接受它。根据 C++20 标准,该表达式合法吗?

static_assert([]<int I>() -> decltype([]<int = {I + I}>{ return true; })
    { return {}; }.template operator()<{}>()());
Run Code Online (Sandbox Code Playgroud)

实例


来自 Clang 的错误消息:

<source>:14:48: error: expected expression
   14 | static_assert([]<int I>() -> decltype([]<int = {I + I}>{ return true; })
      |                                                ^
<source>:15:40: error: expected expression
   15 |     { return {}; }.template operator()<{}>()());
      | 
Run Code Online (Sandbox Code Playgroud)

来自 MSVC 的错误消息:

<source>(14): error C2065: 'I': undeclared identifier
<source>(15): error C3889: call to object of class type '<lambda_1>': no matching
call operator found
<source>(14): note: could be 'auto <lambda_1>::operator ()(void) const'
<source>(15): note: 'auto <lambda_1>::operator ()(void) const': could not deduce
template argument for '_T1'
Run Code Online (Sandbox Code Playgroud)