https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94746
--- Comment #3 from Alejandro Colomar <colomar.6.4.3 at gmail dot com> ---
I tried to use ``#pragma GCC diagnostic`` to enable ``-Wsystem-headers`` only
for that macro. It bloated me with completely unrelated errors from libraries.
So it is not an option.
The only workaround right now is to use a ``_Static_assert``:
.. code-block:: c
#include <sys/cdefs.h>
#define is_same_type(a, b) \
__builtin_types_compatible_p(__typeof__(a), __typeof__(b))
#define is_array(a) (!is_same_type((a), &(a)[0]))
#define Static_assert_array(a) \
_Static_assert(is_array(a), "Not a `[]` !")
#define ARRAY_SIZE(arr) __extension__( \
{ \
Static_assert_array(arr); \
__arraycount((arr)); \
} \
)
This macro is safe no matter which warnings are enabled. There is no other way
to write a safe macro in a system library for calculating the size of an array.
I would call that a bug. The warning is completely useless, unless you keep
copy&pasting that macro for each and every project, which is of course *wrong*.