re PR c/85318 (-Wc90-c99-compat does not warn about for loop initial declarations)
authorMarek Polacek <polacek@redhat.com>
Thu, 7 Jun 2018 19:15:45 +0000 (19:15 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 7 Jun 2018 19:15:45 +0000 (19:15 +0000)
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
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wc90-c99-compat-10.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wc90-c99-compat-11.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wc90-c99-compat-12.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wc90-c99-compat-9.c [new file with mode: 0644]

index 1be683d2c81379547e4f5d7a06abb7de7bb602ba..fa9dca077ee98864a923dc0d5da8bd90638c4e4e 100644 (file)
@@ -1,3 +1,9 @@
+2018-06-07  Marek Polacek  <polacek@redhat.com>
+
+       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  <dave.pagan@oracle.com>
 
        PR c/55976
index 54f58a56cde6db5b33e905d4e6b86e94ae9c3913..af16cfd40bc2911c945b03e1d2e5a8232768c16f 100644 (file)
@@ -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
index 272cb03f80c7fe93378c8aa0ef41c531fc92624c..fffbf9140c2c360b612687311f99ab4afa1823ea 100644 (file)
@@ -1,3 +1,11 @@
+2018-06-07  Marek Polacek  <polacek@redhat.com>
+
+       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  <ni1d@arrl.net>
 
        * 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 (file)
index 0000000..c419ec5
--- /dev/null
@@ -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 (file)
index 0000000..12f9d27
--- /dev/null
@@ -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 (file)
index 0000000..37f2e85
--- /dev/null
@@ -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 (file)
index 0000000..8bd996c
--- /dev/null
@@ -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);
+}