以下程序无法在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 。它由R265787引入,并在9.3版中进行了修订。
您是否尝试过不再使用C ++?