https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102558
Bug ID: 102558 Summary: missing warning comparing T[static N] to null Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- This is the diagnostic part of pr102556: The C99 [static N] array notation in a function parameter indicates that the caller must provide as an argument an array with at least N element. Therefore, in the body of the function, the parameter may be assumed to be nonnull, the same way as if it had been declared with attribute nonnull. The test case below shows that GCC fails to issue a warning for the pointless equality expression in g(), equivalent to the one in f() (although -Waddress might be more suitable than than -Wnonnull-compare). $ cat z.c && gcc -O2 -S -Wall z.c __attribute__ ((nonnull)) int f (int *a) { return a == 0; // warning (good, folded to false) } int g (int a[static 1]) { return a == 0; // missing warning (not folded) } z.c: In function ‘f’: z.c:3:12: warning: ‘nonnull’ argument ‘a’ compared to NULL [-Wnonnull-compare] 3 | return a == 0; // warning (good, folded to false) | ~~^~~~