From e4d44a372485acd8c0aca706221f1bfb880ce6f3 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 7 Jun 2018 19:15:45 +0000 Subject: [PATCH] re PR c/85318 (-Wc90-c99-compat does not warn about for loop initial declarations) PR c/85318 * c-decl.c (check_for_loop_decls): Add -Wc90-c99-compat warning about for loop initial declarations. * gcc.dg/Wc90-c99-compat-10.c: New test. * gcc.dg/Wc90-c99-compat-11.c: New test. * gcc.dg/Wc90-c99-compat-12.c: New test. * gcc.dg/Wc90-c99-compat-9.c: New test. From-SVN: r261293 --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-decl.c | 4 ++++ gcc/testsuite/ChangeLog | 8 ++++++++ gcc/testsuite/gcc.dg/Wc90-c99-compat-10.c | 12 ++++++++++++ gcc/testsuite/gcc.dg/Wc90-c99-compat-11.c | 12 ++++++++++++ gcc/testsuite/gcc.dg/Wc90-c99-compat-12.c | 12 ++++++++++++ gcc/testsuite/gcc.dg/Wc90-c99-compat-9.c | 12 ++++++++++++ 7 files changed, 66 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/Wc90-c99-compat-10.c create mode 100644 gcc/testsuite/gcc.dg/Wc90-c99-compat-11.c create mode 100644 gcc/testsuite/gcc.dg/Wc90-c99-compat-12.c create mode 100644 gcc/testsuite/gcc.dg/Wc90-c99-compat-9.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 1be683d2c81..fa9dca077ee 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2018-06-07 Marek Polacek + + PR c/85318 + * c-decl.c (check_for_loop_decls): Add -Wc90-c99-compat warning about + for loop initial declarations. + 2018-05-30 David Pagan PR c/55976 diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 54f58a56cde..af16cfd40bc 100644 --- a/gcc/c/c-decl.c +++ b/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 % loop " + "initial declarations"); + /* C99 subclause 6.8.5 paragraph 3: [#3] The declaration part of a for statement shall only diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 272cb03f80c..fffbf9140c2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2018-06-07 Marek Polacek + + PR c/85318 + * gcc.dg/Wc90-c99-compat-10.c: New test. + * gcc.dg/Wc90-c99-compat-11.c: New test. + * gcc.dg/Wc90-c99-compat-12.c: New test. + * gcc.dg/Wc90-c99-compat-9.c: New test. + 2018-06-07 Paul Koning * gcc.c-torture/compile/20180605-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/Wc90-c99-compat-10.c b/gcc/testsuite/gcc.dg/Wc90-c99-compat-10.c new file mode 100644 index 00000000000..c419ec52be0 --- /dev/null +++ b/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 a/gcc/testsuite/gcc.dg/Wc90-c99-compat-11.c b/gcc/testsuite/gcc.dg/Wc90-c99-compat-11.c new file mode 100644 index 00000000000..12f9d27b7ac --- /dev/null +++ b/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 a/gcc/testsuite/gcc.dg/Wc90-c99-compat-12.c b/gcc/testsuite/gcc.dg/Wc90-c99-compat-12.c new file mode 100644 index 00000000000..37f2e85423c --- /dev/null +++ b/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 a/gcc/testsuite/gcc.dg/Wc90-c99-compat-9.c b/gcc/testsuite/gcc.dg/Wc90-c99-compat-9.c new file mode 100644 index 00000000000..8bd996c8c25 --- /dev/null +++ b/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); +} -- 2.30.2