From: Willy Tarreau Date: Fri, 7 Apr 2023 12:54:36 +0000 (+0200) Subject: MINOR: compiler: define a __attribute__warning() macro X-Git-Tag: v2.8-dev7~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d4991271486975b245e4607d535b2e4b662981fc;p=thirdparty%2Fhaproxy.git MINOR: compiler: define a __attribute__warning() macro __attribute__((deprecated)) is convenient to discourage from using something deprecated, but gcc >= 4.3 provides __attribute__((warning(x))) that allows to display a specific warning if something is used. This is particularly convenient to give indications when some API parts need to be adapted. Let's just define it as a macro that falls back to the older deprecated attribute when not available. It's supported on clang 14 as well but works differently and errors out when redefined (while the main purpose precisely is to add such a redefinition). Thus instead on clang we use deprecated(msg) which is OK. See https://github.com/llvm/llvm-project/issues/56519 --- diff --git a/include/haproxy/compiler.h b/include/haproxy/compiler.h index 3e00493768..86d4ddf5a7 100644 --- a/include/haproxy/compiler.h +++ b/include/haproxy/compiler.h @@ -90,6 +90,25 @@ #define __attribute__(x) __attribute__(x) #endif +/* attribute(warning) was added in gcc 4.3 */ +#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) +# define __has_attribute_warning 1 +#endif + +/* __attribute__warning(x) does __attribute__((warning(x))) if supported by the + * compiler, otherwise __attribute__((deprecated)). Clang supports it since v14 + * but is a bit capricious in that it refuses a redefinition with a warning + * attribute that wasn't there the first time. However it's OK with deprecated(x) + * so better use this one. See: https://github.com/llvm/llvm-project/issues/56519 + */ +#if defined(__clang__) +# define __attribute__warning(x) __attribute__((deprecated(x))) +#elif __has_attribute(warning) +# define __attribute__warning(x) __attribute__((warning(x))) +#else +# define __attribute__warning(x) __attribute__((deprecated)) +#endif + /* By default, gcc does not inline large chunks of code, but we want it to * respect our choices. */