public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/108986] New: Incorrect warning for [static] array parameter
@ 2023-03-01 18:35 Keith.S.Thompson at gmail dot com
  2023-03-01 18:41 ` [Bug c/108986] " Keith.S.Thompson at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Keith.S.Thompson at gmail dot com @ 2023-03-01 18:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108986
           Summary: Incorrect warning for [static] array parameter
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Keith.S.Thompson at gmail dot com
  Target Milestone: ---

When a parameter is declared with the (new in C99) [static] syntax, and
the argument is a null pointer, the warning incorrectly refers to the
expected size in bytes of the parameter rather than to its length.

That by itself might be annoying but not incorrect, but the warning
includes C syntax that is inconsistent with the actual declaration.

(When the argument is an array object that's too short, the warning
is different. It also refers to a size in bytes, and IMHO referring
to the length would be clearer. Details to follow in a comment.)

$ cat c.c
#include <stddef.h>

void f(int a[static 7]) { }

int main(void) {
    f(NULL);
}
$ gcc --version | head -n 1
gcc (GCC) 12.2.0
$ gcc -Wall -c c.c 
c.c: In function ‘main’:
c.c:6:5: warning: argument 1 to ‘int[static 28]’ is null where non-null
expected [-Wnonnull]
    6 |     f(NULL);
      |     ^~~~~~~
c.c:3:6: note: in a call to function ‘f’
    3 | void f(int a[static 7]) { }
      |      ^
c.c:6:5: warning: argument 1 to ‘int[static 28]’ is null where non-null
expected [-Wnonnull]
    6 |     f(NULL);
      |     ^~~~~~~
c.c:3:6: note: in a call to function ‘f’
    3 | void f(int a[static 7]) { }
      |      ^
$

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

end of thread, other threads:[~2023-08-04 14:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01 18:35 [Bug c/108986] New: Incorrect warning for [static] array parameter Keith.S.Thompson at gmail dot com
2023-03-01 18:41 ` [Bug c/108986] " Keith.S.Thompson at gmail dot com
2023-03-02 10:11 ` rguenth at gcc dot gnu.org
2023-03-02 15:42 ` [Bug c/108986] [11/12/13 Regression] " jakub at gcc dot gnu.org
2023-03-02 18:09 ` jakub at gcc dot gnu.org
2023-03-03 15:12 ` cvs-commit at gcc dot gnu.org
2023-03-03 15:19 ` [Bug c/108986] [11/12 " jakub at gcc dot gnu.org
2023-03-19  5:30 ` cvs-commit at gcc dot gnu.org
2023-03-20 10:28 ` [Bug c/108986] [11 " jakub at gcc dot gnu.org
2023-05-08 12:26 ` rguenth at gcc dot gnu.org
2023-08-04 14:06 ` muecker at gwdg dot de

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).