Bug 67243 - Wrong Message of -Wvla for Standard ISO C90 However Emitted with -std=c11
Summary: Wrong Message of -Wvla for Standard ISO C90 However Emitted with -std=c11
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, documentation
: 67230 67231 67232 67233 67234 67235 67236 67237 71925 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-08-16 22:12 UTC by Chengnian Sun
Modified: 2016-07-19 03:32 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-08-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chengnian Sun 2015-08-16 22:12:09 UTC
When I compile the code "int array[4.3];", in addition to the error, GCC also emits a -Wvla warning saying that ISO C90 forbids this. However, I specify -std=c11 in the command line, and IMHO this is at least an inconsistency between errors and error messages. 

$: cat t.c
int array[4.3];
$: gcc-trunk -c -Wvla -std=c11 -pedantic t.c
t.c:1:5: error: size of array ‘array’ has non-integer type
 int array[4.3];
     ^
t.c:1:1: warning: variably modified ‘array’ at file scope
 int array[4.3];
 ^
t.c:1:1: warning: ISO C90 forbids array ‘array’ whose size can’t be evaluated [-Wvla]
$: gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk/configure --enable-languages=c,c++,objc,obj-c++,fortran,lto --disable-werror --with-gmp=/usr/local/gcc-trunk --with-mpfr=/usr/local/gcc-trunk --with-mpc=/usr/local/gcc-trunk --with-cloog=/usr/local/gcc-trunk --prefix=/usr/local/gcc-trunk
Thread model: posix
gcc version 6.0.0 20150815 (experimental) [trunk revision 226911] (GCC) 
$:
Comment 1 Manuel López-Ibáñez 2015-08-16 22:30:21 UTC
It is also useless to give such warning after such error.

I'm afraid the way GCC reports most extensions is very fragile in this way. It doesn't affect only Wvla. It would be nice to discuss/design/agree on a canonical and future-proof way to report:

* Pure GNU extensions, not accepted by any standard.
* Features accepted by some standard but that are extensions for other standards (like C++ style comments).

The latter requires some future-proof way of reporting:

* Extensions that are forbidden up to a particular standard.

* Extensions that were accepted but are forbidden now (not sure if there is such case at all).

(It is kind of ironic that Clang is fair more clear pointing out when something is a "GNU extension". In some way, Clang is doing more promotion of GNU than GCC!)
Comment 2 Manuel López-Ibáñez 2015-08-16 22:36:40 UTC
Moreover, since VLAs are not an extension in C99, the text of Wvla is wrong always for -std=c99. 

void square(int num) {
  int array[num];
}

With -std=c99 -Wpedantic there is no warning.
With -std=c99 -Wvla, it mentions ISO C90, which is irrelevant.
Clang just says: "variable length array used"
Comment 3 Marek Polacek 2015-08-18 11:49:57 UTC
*** Bug 67237 has been marked as a duplicate of this bug. ***
Comment 4 Marek Polacek 2015-08-18 11:50:06 UTC
*** Bug 67236 has been marked as a duplicate of this bug. ***
Comment 5 Marek Polacek 2015-08-18 11:50:16 UTC
*** Bug 67235 has been marked as a duplicate of this bug. ***
Comment 6 Marek Polacek 2015-08-18 11:50:23 UTC
*** Bug 67234 has been marked as a duplicate of this bug. ***
Comment 7 Marek Polacek 2015-08-18 11:50:27 UTC
*** Bug 67233 has been marked as a duplicate of this bug. ***
Comment 8 Marek Polacek 2015-08-18 11:50:35 UTC
*** Bug 67232 has been marked as a duplicate of this bug. ***
Comment 9 Marek Polacek 2015-08-18 11:50:41 UTC
*** Bug 67231 has been marked as a duplicate of this bug. ***
Comment 10 Marek Polacek 2015-08-18 11:50:48 UTC
*** Bug 67230 has been marked as a duplicate of this bug. ***
Comment 11 Chengnian Sun 2015-08-18 16:47:59 UTC
(In reply to Marek Polacek from comment #10)
> *** Bug 67230 has been marked as a duplicate of this bug. ***

Sorry, Marek. 

I did not realize that I had submitted so many duplicate reports. I got gateway errors from GCC bugzilla that night when I was submitting this bug report. I tried several times and it seems they all went through despite the errors.
Comment 12 Marek Polacek 2015-08-18 16:49:10 UTC
No problem.  I suspected it was something like that.
Comment 13 Marek Polacek 2015-09-18 13:26:38 UTC
Another case is -Wdeclaration-after-statement:

int
fn (int m)
{
  if (m > 0)
    return -1;
  int a;
}
Comment 14 Martin Sebor 2016-07-19 03:29:34 UTC
*** Bug 71925 has been marked as a duplicate of this bug. ***