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

            Bug ID: 98541
           Summary: warning with -Wnonnull for array parameter with bound
                    > 0
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: muecker at gwdg dot de
  Target Milestone: ---

In the example

void foo(int n, double x[n]);

void f(void)
{
        foo(1, 0);
}

there is a warning

x.c: In function ‘f’:
x.c:7:9: warning: argument 1 of variable length array ‘double[n]’ is null but
the corresponding bound argument 2 value is 1 [-Wnonnull]
    7 |         foo(1, 0);
      |         ^~~~~~~~~
x.c:3:6: note: in a call to function ‘foo’
    3 | void foo(int n, double x[n]);
      |      ^~~


But the bound > 0 does not imply that 'x' is not NULL. (static would imply
this). There is also no warning with a constant bound > 0.


Passing NULL is useful for optional arguments and when the bound is shared
between different parameters, it can not be passed as zero.

Reply via email to