diff --git a/glib/gmacros.h b/glib/gmacros.h index 9c36e9925..a047d0ea2 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -779,6 +779,38 @@ #define GLIB_CANNOT_IGNORE_DEPRECATIONS #endif +/** + * G_GNUC_FLAG_ENUM: + * + * Expands to the GNU C `flag_enum` attribute if the compiler is gcc or clang. + * This attribute indicates that an enumerated type is used in bitwise + * operations. + * It is sometimes used in static analysis. + * + * See the + * [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-flag_005fenum-type-attribute) + * for details. + * + * |[ + * typedef enum { + * G_KEY_FILE_NONE = 0, + * G_KEY_FILE_KEEP_COMMENTS = 1 << 0, + * G_KEY_FILE_KEEP_TRANSLATIONS = 1 << 1 + * } G_GNUC_FLAG_ENUM GKeyFileFlags; + * ]| + * + * (The attribute can also be placed after `enum` and before the opening brace, + * but that may cause it to be misinterpreted as the name of the enum if the + * macro is not defined.) + * + * Since: 2.88 + */ +#if g_macro__has_attribute(flag_enum) +#define G_GNUC_FLAG_ENUM __attribute__((flag_enum)) +#else +#define G_GNUC_FLAG_ENUM +#endif + /** * G_GNUC_MAY_ALIAS: *