具有显式返回类型的Lambda上的函数属性无法编译

问题描述 投票:0回答:2

以下程序无法在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错误还是我做错了?

c++ g++
2个回答
1
投票

这是GCC错误Bug 90333 - [9 Regression] Can't apply attributes to lambdas with trailing returns 。它由R265787引入,并在9.3版中进行了修订。


0
投票

您是否尝试过不再使用C ++?

© www.soinside.com 2019 - 2024. All rights reserved.