BUILD: compiler: fix __equals_1() on older compilers

It appeared that __has_attribute() doesn't work on gcc 4.4 and older
because the concatenation of __has_attribute##x isn't resolved as a one
before being passed to __equals_1() which immediately concatenates it to
comma_for_one. We first need to pass it through an extra layer to resolve
this name to a value. The new version was tested with gcc 4.2 to 11.3.

This may be backported though it's pretty minor.
This commit is contained in:
Willy Tarreau 2023-04-07 14:34:38 +02:00
parent ad44939e40
commit 988e19c607

View File

@ -50,9 +50,10 @@
* second one.
*/
#define comma_for_one1 ,
#define ____equals_1(x, y, ...) (y)
#define ___equals_1(x, ...) ____equals_1(x, 0)
#define __equals_1(x) ___equals_1(comma_for_one ## x 1)
#define _____equals_1(x, y, ...) (y)
#define ____equals_1(x, ...) _____equals_1(x, 0)
#define ___equals_1(x) ____equals_1(comma_for_one ## x 1)
#define __equals_1(x) ___equals_1(x)
/* 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.