clang supports several advanced __attribute__ cases that gcc does not, and two strike me as particularly useful: enable_if and diagnose_if. You can find the documentation on those here: https://clang.llvm.org/docs/AttributeReference.html#diagnose-if https://clang.llvm.org/docs/AttributeReference.html#enable-if Basically, diagnose_if allows to add custom warning messages, think of it as a superset of the nonnull attribute. This could be a great tool to improve code quality, if applied to an API from a library. enable_if is much more complex and probably a lot harder to implement. It allows to have a special case version of a library function and use the attribute to tell the compiler to call it if the compiler knows the special case is true. For example, one could have a special memset version that does not need to do alignment handling if the compiler can tell that the destination buffer is 16 byte aligned.
Confirmed. I think a feature along these lines could be useful as a generalization of some existing warnings (such as -Walloc-zero, -Walloc-size-larger-than, or -Wnonnull) and future ones like those. An aspect of the attribute that might be worth handling differently in GCC than in Clang is whether the checking should be restricted to just arguments that are constant expressions or also applied to arguments that are the result of constant or value range propagation (or perhaps even other forms of optimization. I think the latter would make it more powerful in GCC, but I wonder if there might also be cases where it could lead to excessive false positives. If there were such cases, generalizing the attribute to specify what kinds of expressions the diagnostic should consider might be worthwhile (i.e., constant expressions only, or even those where the expression is known to have a value or be in some range as a result of various optimizations).
This could be used to implement SFINAE friendly, warning free <compare> operators See https://github.com/llvm/llvm-project/pull/79465 https://godbolt.org/z/1xr9Wx38T