From: Aki Tuomi Date: Tue, 11 Aug 2020 05:41:54 +0000 (+0300) Subject: lib: macros - Add ENUM_NEGATE X-Git-Tag: 2.3.13~81 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3698334932744c34d42878d43754d06c2a232e30;p=thirdparty%2Fdovecot%2Fcore.git lib: macros - Add ENUM_NEGATE Handles enumeration flag negation. --- diff --git a/src/lib/macros.h b/src/lib/macros.h index 6a3c7f45b1..7e67a4d16d 100644 --- a/src/lib/macros.h +++ b/src/lib/macros.h @@ -280,3 +280,7 @@ # define ATTR_NO_SANITIZE_INTEGER # define ATTR_NO_SANITIZE_IMPLICIT_CONVERSION #endif + +/* negate enumeration flags in a way that avoids implicit conversion */ +#define ENUM_NEGATE(x) \ + ((unsigned int)(~(x)) + COMPILE_ERROR_IF_TRUE(sizeof((x)) > sizeof(int) || (x) < 0 || (x) > INT_MAX))