I found out that the macro `#define __arraycount(__x) (sizeof(__x) / sizeof(__x))` which is in libbsd's <sys/cdefs.h> doesn't trigger any warning when applied to a pointer.
I investigated the reason, and I found out that my own `#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)))` doesn't trigger any warnings either (it is installed in `/usr/local/include/`, but it does trigger warnings when compiling before installing it.
So I came to the conclusion that the bug is the following:
GCC suppresses warnings in system headers, which of course is a generally good thing, but in this case it is not a good thing.
Maybe a solution would be to not suppress warnings about macros defined in system headers (this might suddenly trigger lots of warnings, some of them maybe unwanted, I don't know). There might be more bugs like this one being ignored.
Code to reproduce the bug:
Minimum compilation settings to reproduce the bug:
$ gcc -Wsizeof-pointer-div bug.c `pkg-config --cflags libbsd-overlay`
I'm not a GCC developer, but this is by design.
Maybe the design is not perfect.
Maybe some special warnings should still be warned about when they are used in user's code. I don't think there are any possible false positives with this warning. But still I don't know.
Maybe I should add a pragma in the system header to enable `-Wsystem-headers` for that macro.
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
#define is_same_type(a, b) \
#define is_array(a) (!is_same_type((a), &(a)))
#define Static_assert_array(a) \
_Static_assert(is_array(a), "Not a `` !")
#define ARRAY_SIZE(arr) __extension__( \
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*.