Message ID | 20180607170114.GF28085@redhat.com |
---|---|
State | New |
Headers | show |
Series | C PATCH for c/85318, missing -Wc90-c99-compat warning with for-init-loop | expand |
On Thu, 7 Jun 2018, Marek Polacek wrote: > This PR reports that we are not emitting a -Wc90-c99-compat warning > for a for loop with a declaration. This patch adds it; here we want > to use pedwarn_c90 which takes care of it. > > Bootstrapped/regtested on x86_64-linux, ok for trunk? OK. (This wasn't present originally because actually using this construct in C90 mode produces a hard error as it's problematic without the C99 block scopes - that is, this pedwarn_c90 is needed only for -Wc90-c99-compat, not for conformance in C90 mode.)
diff --git gcc/c/c-decl.c gcc/c/c-decl.c index 54f58a56cde..729187c79e9 100644 --- gcc/c/c-decl.c +++ gcc/c/c-decl.c @@ -9608,6 +9608,10 @@ check_for_loop_decls (location_t loc, bool turn_off_iso_c99_error) } return NULL_TREE; } + else + pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support %<for%> loop " + "initial declarations"); + /* C99 subclause 6.8.5 paragraph 3: [#3] The declaration part of a for statement shall only diff --git gcc/testsuite/gcc.dg/Wc90-c99-compat-10.c gcc/testsuite/gcc.dg/Wc90-c99-compat-10.c index e69de29bb2d..c419ec52be0 100644 --- gcc/testsuite/gcc.dg/Wc90-c99-compat-10.c +++ gcc/testsuite/gcc.dg/Wc90-c99-compat-10.c @@ -0,0 +1,12 @@ +/* PR c/85318 */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu11 -Wc90-c99-compat -pedantic-errors" } */ + +extern void bar (int); + +void +foo (int n) +{ + for (int i = 0; i < n; i++) /* { dg-warning "ISO C90 does not support .for. loop" } */ + bar (i); +} diff --git gcc/testsuite/gcc.dg/Wc90-c99-compat-11.c gcc/testsuite/gcc.dg/Wc90-c99-compat-11.c index e69de29bb2d..12f9d27b7ac 100644 --- gcc/testsuite/gcc.dg/Wc90-c99-compat-11.c +++ gcc/testsuite/gcc.dg/Wc90-c99-compat-11.c @@ -0,0 +1,12 @@ +/* PR c/85318 */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu11 -Wc90-c99-compat -Wno-pedantic" } */ + +extern void bar (int); + +void +foo (int n) +{ + for (int i = 0; i < n; i++) /* { dg-warning "ISO C90 does not support .for. loop" } */ + bar (i); +} diff --git gcc/testsuite/gcc.dg/Wc90-c99-compat-12.c gcc/testsuite/gcc.dg/Wc90-c99-compat-12.c index e69de29bb2d..37f2e85423c 100644 --- gcc/testsuite/gcc.dg/Wc90-c99-compat-12.c +++ gcc/testsuite/gcc.dg/Wc90-c99-compat-12.c @@ -0,0 +1,12 @@ +/* PR c/85318 */ +/* { dg-do compile } */ +/* { dg-options "-Wpedantic" } */ + +extern void bar (int); + +void +foo (int n) +{ + for (int i = 0; i < n; i++) /* { dg-bogus "ISO C90 does not support .for. loop" } */ + bar (i); +} diff --git gcc/testsuite/gcc.dg/Wc90-c99-compat-9.c gcc/testsuite/gcc.dg/Wc90-c99-compat-9.c index e69de29bb2d..8bd996c8c25 100644 --- gcc/testsuite/gcc.dg/Wc90-c99-compat-9.c +++ gcc/testsuite/gcc.dg/Wc90-c99-compat-9.c @@ -0,0 +1,12 @@ +/* PR c/85318 */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wc90-c99-compat -pedantic-errors" } */ + +extern void bar (int); + +void +foo (int n) +{ + for (int i = 0; i < n; i++) /* { dg-warning "ISO C90 does not support .for. loop" } */ + bar (i); +}