public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/94746] New: -Wsizeof-pointer-div not triggered by system header macros
@ 2020-04-24 13:39 colomar.6.4.3 at gmail dot com
  2020-04-25 19:10 ` [Bug c/94746] " asolokha at gmx dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: colomar.6.4.3 at gmail dot com @ 2020-04-24 13:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94746

            Bug ID: 94746
           Summary: -Wsizeof-pointer-div not triggered by system header
                    macros
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: colomar.6.4.3 at gmail dot com
  Target Milestone: ---

I found out that the macro `#define __arraycount(__x) (sizeof(__x) /
sizeof(__x[0]))` 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)[0]))` 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:

#include <sys/cdefs.h>

int main(void)
{
        int *p;

        return  __arraycount(p);
}

Minimum compilation settings to reproduce the bug:

$ gcc -Wsizeof-pointer-div bug.c `pkg-config --cflags libbsd-overlay`

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-05-15  7:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-24 13:39 [Bug c/94746] New: -Wsizeof-pointer-div not triggered by system header macros colomar.6.4.3 at gmail dot com
2020-04-25 19:10 ` [Bug c/94746] " asolokha at gmx dot com
2020-04-25 22:15 ` colomar.6.4.3 at gmail dot com
2020-04-26  0:08 ` colomar.6.4.3 at gmail dot com
2024-05-15  7:00 ` alx at kernel dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).