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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
                 CC|                            |msebor at gcc dot gnu.org
   Last reconfirmed|                            |2021-01-06

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Both the warning in the VLA case and its absence in the ordinary case are by
design.

The VLA case gets a warning because it seems suspicious to specify a nonzero
number of elements for an array and then null as the array (the VLA parameter
can be null when the bound is zero).  But I didn't consider the shared bound
use case so I suppose the warning could be relaxed to accommodate it, and
either changed to rely on the [static] for the bound as you suggest or on the
VLA parameter declared with attribute nonnull.  I can't think of a use case
where the bound isn't shared and where setting it to nonzero and passing a null
pointer would not be a bug.

My rationale for not issuing a warning for ordinary arrays with constant bounds
is that those are commonly treated as "optional," and so there relying on some
additional notation ([static] or nonnull) seems appropriate and necessary to
prevent this use case.

Reply via email to