Travis Gockel
Travis Gockel

Reputation: 27663

Function Attribute on Lambda with Explicit Return Type fails to Compile

The following program fails to compile in g++ 9.1 and 9.2 (with --std=c++17):

int main()
{
    auto foo = [&]() __attribute__((always_inline)) -> bool { return true; };
}

With the following error:

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; };
      |                                                        ^~~~

This program successfully compiles with g++ 4.7 to 8.3, as well as clang++ from 3.5 to 9.0. Is this a GCC bug or am I doing something wrong?

Upvotes: 0

Views: 173

Answers (1)

Travis Gockel
Travis Gockel

Reputation: 27663

This is GCC bug Bug 90333 - [9 Regression] Can't apply attributes to lambdas with trailing returns . It was introduced with R265787 and is slated as fixed in 9.3.

Upvotes: 1

Related Questions