[Bug c/59520] a possible inconsistency in error diagnostics with "-pedantic -std=c99"

manu at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Dec 18 10:50:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59520

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org

--- Comment #2 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to joseph@codesourcery.com from comment #1)
> The main concerns for diagnostics in such cases are (a) that they are 
> meaningful and (b) that invalid code gets at least one error with 
> -pedantic-errors, and at least one warning or error with -pedantic.  
> There may be less consistency in what's a warning / error if -pedantic 
> rather than -pedantic-errors is used.

So merely using -pedantic may produce errors that do not appear without
-pedantic? Is that really a desired behavior?

Also,

$ cc1 -std=c99 -pedantic test.c
test.c:1:5: warning: ISO C forbids zero-size array ‘a’ [-Wpedantic]
 int a[0] = {};
     ^
test.c:1:12: warning: ISO C forbids empty initializer braces [-Wpedantic]
 int a[0] = {};
            ^
test.c:2:11: warning: ISO C forbids empty initializer braces [-Wpedantic]
 int b[] = {};
           ^
test.c:2:5: error: zero or negative size array ‘b’
 int b[] = {};
     ^
test.c:3:5: warning: array ‘c’ assumed to have one element [enabled by default]
 int c[];
     ^

Note that a[0] = {} gives a warning but "b[] = {}" gives a hard error.

Clang seems much more consistent here:

test.c:1:7: warning: zero size arrays are an extension [-Wzero-length-array]
int a[0] = {};
      ^
test.c:1:12: warning: use of GNU empty initializer extension
[-Wgnu-empty-initializer]
int a[0] = {};
           ^
test.c:2:11: warning: use of GNU empty initializer extension
[-Wgnu-empty-initializer]
int b[] = {};
          ^
test.c:2:11: warning: zero size arrays are an extension [-Wzero-length-array]
test.c:3:5: warning: tentative array definition assumed to have one element
int c[];
    ^

Note that clang gives exactly the same warning for "a[0] = {}" and "b[] = {}".


More information about the Gcc-bugs mailing list