https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79459
Bug ID: 79459
Summary: Please add enable_if and diagnose_if attributes (from
clang)
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: felix-gcc at fefe dot de
Target Milestone: ---
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.