You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, we use a bunch of compiler-specific attributes: for example Py_UNUSED is defined for GCC using __attribute__(( unused )) (in a #ifdef __GNUC__ block).
This makes for a bit of a problem for non-mainstream compilers: either they define __GNUC__ to pretend they're GCC, which means they need to implement "all" of GCC's quirks, or they don't, and they don't get nice features & optimizations.
C++17 & C23 have a solution to this: the [[attribute]] syntax. You can use [[maybe_unused]] (standard C) or [[gnu::unused]] (compiler-specific), after checking availability with #if defined(__has_c_attribute) && __has_c_attribute(maybe_unused).
Other compilers can then only provide the specific attribute to get the benefit. (Providing __has_c_attribute(gnu::unused) only means that this one feature behaves like in GCC.)
Like many new C/C++ features, existing compilers implement it in older-standard-mode as extensions. (And this is all about compiler extensions.)
We should start slowly migrating to this, see how it interacts with various pedantic modes we need to support. (Alas, this part is tricky.)
Presumably, any future attributes will be exposed this way; we should be ready to use them without compiler-specific #if ladders.
Activity