public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/98541] New: warning with -Wnonnull for array parameter with bound > 0
@ 2021-01-05 16:12 muecker at gwdg dot de
  2021-01-06 18:08 ` [Bug c/98541] " msebor at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: muecker at gwdg dot de @ 2021-01-05 16:12 UTC (permalink / raw)
  To: gcc-bugs

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.

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

end of thread, other threads:[~2023-11-04 10:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 16:12 [Bug c/98541] New: warning with -Wnonnull for array parameter with bound > 0 muecker at gwdg dot de
2021-01-06 18:08 ` [Bug c/98541] " msebor at gcc dot gnu.org
2021-01-06 18:12 ` msebor at gcc dot gnu.org
2021-01-06 19:06 ` muecker at gwdg dot de
2023-11-03 22:21 ` cvs-commit at gcc dot gnu.org
2023-11-04 10:01 ` uecker at gcc dot gnu.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).