This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C PATCH for c/85318, missing -Wc90-c99-compat warning with for-init-loop
- From: Marek Polacek <polacek at redhat dot com>
- To: Joseph Myers <joseph at codesourcery dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 7 Jun 2018 13:01:14 -0400
- Subject: C PATCH for c/85318, missing -Wc90-c99-compat warning with for-init-loop
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?
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.
* 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.
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);
+}