[PATCH]: Add a new option -Wvariable-length-array

Seongbae Park seongbae.park@gmail.com
Wed Feb 7 06:16:00 GMT 2007


On 2/6/07, Joseph S. Myers <joseph@codesourcery.com> wrote:
> On Tue, 6 Feb 2007, Seongbae Park wrote:
>
> > Thanks to Joseph's comment, now the logic is different -
> > -pedantic overrides -Wno-variable-length-array,
> > and they have different messages so they are not identical.
>
> My comment was about -pedantic-errors -Wvariable-length-array, not about
> the -Wno-variable-length-array case.
>
> I agree that -Wno-variable-length-array should disable the diagnostic from
> -pedantic/-pedantic-errors.
>
> --
> Joseph S. Myers
> joseph@codesourcery.com

Ok. Does the following behavior look reasonable ?

# cat vla.c
int test(int i, char a[i]);
# sh -v x
...
$gcc vla.c -c
$gcc vla.c -c -pedantic
vla.c:1: warning: ISO C90 forbids variable length array 'a'
$gcc vla.c -c -pedantic-errors
vla.c:1: error: ISO C90 forbids variable length array 'a'
$gcc vla.c -c -Wvariable-length-array
vla.c:1: warning: variable length array 'a' is used
$gcc vla.c -c -Wvariable-length-array -pedantic
vla.c:1: warning: ISO C90 forbids variable length array 'a'
$gcc vla.c -c -Wvariable-length-array -pedantic-errors
vla.c:1: error: ISO C90 forbids variable length array 'a'
$gcc vla.c -c -Wno-variable-length-array
$gcc vla.c -c -Wno-variable-length-array -pedantic
$gcc vla.c -c -Wno-variable-length-array -pedantic-errors
#


In short, -Wvariable-length-array will enable the warning.
-Wno-varibale-length-array will prevent the warning
even with -pedantic/-pedantic-error.

In terms of when to use those flags:
 -Wvariable-length-array flag is useful
for enforcing the coding style that doesn't allow variable length array.
-Wno-variable-length-array flag is useful
if -pedantic users don't want to see the warning about variable length array.

I'll send out a patch if this looks reasonable.
Note that this is different from -W[no-]long-long.
Wno-long-long prevents the warning
but -Wlong-long itself doesn't enable the warning -
it has to be combined with -pedantic.

The difference in this case, is that I think it's useful
to have -Wvariable-length-array issue the warning
even *without* -pedantic,
as the goal is to help enforcing a coding style
that doesn't allow variable length array.

Regardless of how we decide,
I'll add testcases to test the combination with -pedantic/-pedantic-errors.
-- 
#pragma ident "Seongbae Park, compiler, http://seongbae.blogspot.com"



More information about the Gcc-patches mailing list