具有显式 Return 类型的 Lambda 函数属性无法编译
Function Attribute on Lambda with Explicit Return Type fails to Compile
以下程序无法在 g++ 9.1 和 9.2(--std=c++17
)中编译:
int main()
{
auto foo = [&]() __attribute__((always_inline)) -> bool { return true; };
}
出现以下错误:
file.cpp: In lambda function:
file.cpp:3:53: error: expected '{' before '->' token
3 | auto foo = [&]() __attribute__((always_inline)) -> bool { return true; };
| ^~
file.cpp: In function 'int main()':
file.cpp:3:53: error: base operand of '->' has non-pointer type 'main()::<lambda()>'
file.cpp:3:56: error: expected unqualified-id before 'bool'
3 | auto foo = [&]() __attribute__((always_inline)) -> bool { return true; };
| ^~~~
此程序成功编译了 g++ 4.7 到 8.3,以及 clang++ 从 3.5 到 9.0。这是 GCC 错误还是我做错了什么?
这是 GCC 错误 Bug 90333 - [9 Regression] Can't apply attributes to lambdas with trailing returns . It was introduced with R265787,预计将在 9.3 中修复。
以下程序无法在 g++ 9.1 和 9.2(--std=c++17
)中编译:
int main()
{
auto foo = [&]() __attribute__((always_inline)) -> bool { return true; };
}
出现以下错误:
file.cpp: In lambda function:
file.cpp:3:53: error: expected '{' before '->' token
3 | auto foo = [&]() __attribute__((always_inline)) -> bool { return true; };
| ^~
file.cpp: In function 'int main()':
file.cpp:3:53: error: base operand of '->' has non-pointer type 'main()::<lambda()>'
file.cpp:3:56: error: expected unqualified-id before 'bool'
3 | auto foo = [&]() __attribute__((always_inline)) -> bool { return true; };
| ^~~~
此程序成功编译了 g++ 4.7 到 8.3,以及 clang++ 从 3.5 到 9.0。这是 GCC 错误还是我做错了什么?
这是 GCC 错误 Bug 90333 - [9 Regression] Can't apply attributes to lambdas with trailing returns . It was introduced with R265787,预计将在 9.3 中修复。