https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107496
Bug ID: 107496
Summary: [Feature request] Conditional attributes
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jwjagersma at gmail dot com
Target Milestone: ---
I'd like to request a new extension feature: the ability to enable or disable
attributes based on a conditional expression.
This could be implemented either via a sort of meta-attribute:
template <bool A, bool B>
[[gnu::conditional(A, always_inline), gnu::conditional(B, noinline)]]
auto f() { /* ... */ }
Or by reusing the template syntax:
template <bool A, bool B>
[[gnu::always_inline<A>, gnu::noinline<B>]]
auto f() { /* ... */ }
Although maybe the latter should only be allowed via the __attribute__ syntax,
which is already a GNU extension.
I did recently send in a small patch to allow selecting a string conditionally
in the i386 'target' attribute (no responses yet though). I really need it for
that particular case, and it would be nice if that could make it in gcc 13, if
there are no objections.
For the longer term though, I think being able to apply this to all attributes
would be a very useful feature to have.