Section

Attribute specifier sequence (since C++11)

Introduces implementation-defined attributes for types, objects, code, etc.

# Notes

The presence of each individual attribute on a given platform can be checked with __has_cpp_attribute preprocessor macro.

# Example

[[gnu::always_inline]] [[gnu::hot]] [[gnu::const]] [[nodiscard]]
inline int f(); // declare f with four attributes
 
[[gnu::always_inline, gnu::const, gnu::hot, nodiscard]]
int f(); // same as above, but uses a single attr specifier that contains four attributes
 
// C++17:
[[using gnu : const, always_inline, hot]] [[nodiscard]]
int f[[gnu::always_inline]](); // an attribute may appear in multiple specifiers
 
int f() { return 0; }
 
int main() {}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
CWG 2079C++11[[ could not appear inside an attribute argumentallowed
CWG 2538C++11it was unclear whether standard attributes can be syntactically ignoredprohibited
CWG 2695C++11it was unclear whether standard attributes can be semantically ignoredprohibited
P2156R1C++11every standard attribute was required to appear at most once in an attribute-listnot required

# See also