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]) { }
      |      ^
$

Reply via email to