[Bug c/98536] warning with -Wvla-parameter for unspecified bound getting specified later

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jan 5 18:08:54 GMT 2021


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning in both cases (reproduced below) is to encourage specifying the
bounds in declarations and discourage the use of [*].  At some point [*] needs
to be replaced by an actual bound so it might as well be done at the point of
the declaration where it can be used by tools for bounds checking.  I see [*]
as analogous to a function without a prototype.  Both have some uses that can't
be easily achieved by other means but both are dangerous and best avoided.

$ gcc -S -Wall pr98536.c
pr98536.c:2:17: warning: argument 1 of type ‘double[3]’ declared as an ordinary
array [-Wvla-parameter]
    2 | void foo(double x[3]) { }
      |          ~~~~~~~^~~~
pr98536.c:1:17: note: previously declared as a variable length array
‘double[*]’
    1 | void foo(double x[*]);
      |          ~~~~~~~^~~~
pr98536.c:5:17: warning: argument 1 of type ‘double[*]’ declared with 1
unspecified variable bound [-Wvla-parameter]
    5 | void bar(double x[*]);
      |          ~~~~~~~^~~~
pr98536.c:6:17: note: subsequently declared as ‘double[n]’ with 0 unspecified
variable bounds
    6 | void bar(double x[n]) { }
      |          ~~~~~~~^~~~


More information about the Gcc-bugs mailing list