https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90333

            Bug ID: 90333
           Summary: Can't apply attributes to lambdas with trailing
                    returns
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patrick.a.moran at gmail dot com
  Target Milestone: ---

In 8.3.0 we could do either one of these:

> []() __attribute__((always_inline)) -> int { return 0; }
> []() [[gnu::always_inline]] -> int { return 0; }

I understand that __attribute__ is a GCC extension, but it's my understanding
that the second one is standard behavior.

As of 9.1.0, the __attribute__ variant both fails with "expected '{' before
'->' token", and the [[gnu::always_inline]] variant fails because it's applying
the attribute to the trailing return type rather than the lambda.

I tried every possible position, but each fails
  * __attribute__((always_inline)) []() -> int { return 0; }
  * [[gnu::always_inline]] []() -> int { return 0; }
    * These fail with "attributes at the beginning of statement are ignored"
    * IE, it's not actually applying to the lambda.
  * [] __attribute__((always_inline)) () -> int { return 0; }
  * [] [[gnu::always_inline]] () -> int { return 0; }
    * These fail with "expected '{' before '[' token" (or "__attribute__")
  * []() __attribute__((always_inline)) -> int { return 0; }
    * This fails with "expected '{' before '->' token
  * []() [[gnu::always_inline]] -> int { return 0; }
    * This fails with "attribute ignored"
    * It is applying the attribute as an attribute of the return type
  * []() -> __attribute__((always_inline)) int { return 0; }
  * []() -> [[gnu::always_inline]] int { return 0; }
    * This fails with "attribute does not apply to types"
    * It is applying the attribute as an attribute of the return type
  * []() -> int [[gnu::always_inline]] { return 0; }
  * []() -> int __attribute__((always_inline)) { return 0; }
    * This fails with "attribute does not apply to types"
    * It is applying the attribute as an attribute of the return type
  * []() -> int { return 0; } __attribute__((always_inline))
    * Fails with "expected ';' before '__attribute__'"
  * []() -> int { return 0; } [[gnu::always_inline]]
    * Fails with "two consecutive '[' shall only introduce an attribute before
'[' token

It would appear that in 9.1.0 there's no way to specify attributes for a lambda
that has a trailing return type?

Reply via email to