From: Willy Tarreau Date: Sun, 13 Nov 2022 10:39:18 +0000 (+0100) Subject: BUILD: compiler: add a default definition for __has_attribute() X-Git-Tag: v2.7-dev9~100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b080f713f61d19a91a1ef27ec0505c20739d508;p=thirdparty%2Fhaproxy.git BUILD: compiler: add a default definition for __has_attribute() It happens that gcc since 5.x has this macro which is only mentioned once in the doc, associated with __builtin_has_attribute(). Clang had it at least since 3.0. In addition it validates #ifdef when present, so it's easy to detect it. Here we're providing a fallback to another macro __has_attribute_ so that it's possible to define that macro to the value 1 for older compilers when the attribute is supported. --- diff --git a/include/haproxy/compiler.h b/include/haproxy/compiler.h index 6c356a69d9..82b6ae4c5e 100644 --- a/include/haproxy/compiler.h +++ b/include/haproxy/compiler.h @@ -49,6 +49,17 @@ #define ___equals_1(x, ...) ____equals_1(x, 0) #define __equals_1(x) ___equals_1(comma_for_one ## x 1) +/* gcc 5 and clang 3 brought __has_attribute(), which is not well documented in + * the case of gcc, but is convenient since handled at the preprocessor level. + * In both cases it's possible to test for __has_attribute() using ifdef. When + * not defined we remap this to the __has_attribute_ macro so that we'll + * later be able to implement on a per-compiler basis those which are missing, + * by defining __has_attribute_ to 1. + */ +#ifndef __has_attribute +#define __has_attribute(x) __equals_1(__has_attribute_ ## x) +#endif + #if !defined(__GNUC__) /* Some versions of glibc irresponsibly redefine __attribute__() to empty for * non-gcc compilers, and as such, silently break all constructors with other