diff options
author | Joseph Myers <joseph@codesourcery.com> | 2023-05-16 23:44:56 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2023-05-16 23:46:02 +0000 |
commit | 036b4eb47e5c6212bdcd5fd9bf4fd08a62b2c65a (patch) | |
tree | 03e67ad881e454a8b0c61577b176b087689efd67 /gcc/testsuite/gcc.dg/c11-fordecl-3.c | |
parent | 509eef9314b24eff20a5dbdd92f6ab52e2c0c786 (diff) | |
download | gcc-036b4eb47e5c6212bdcd5fd9bf4fd08a62b2c65a.tar.gz |
c: Remove restrictions on declarations in 'for' loops for C2X
C2X removes a restriction that the only declarations in the
declaration part of a 'for' loop are declarations of objects with
storage class auto or register. Implement this change, making the
diagnostics into pedwarn_c11 calls instead of errors (as usual for
features added in a new standard version that were invalid code in a
previous version), so now pedwarn-if-pedantic for older standards and
diagnosed also with -Wc11-c2x-compat.
Bootstrapped with no regressions for x86_64-pc-linux-gnu.
gcc/c/
* c-decl.cc (check_for_loop_decls): Use pedwarn_c11 for
diagnostics.
gcc/testsuite/
* gcc.dg/c11-fordecl-1.c, gcc.dg/c11-fordecl-2.c,
gcc.dg/c11-fordecl-3.c, gcc.dg/c11-fordecl-4.c,
gcc.dg/c2x-fordecl-1.c, gcc.dg/c2x-fordecl-2.c,
gcc.dg/c2x-fordecl-3.c, gcc.dg/c2x-fordecl-4.c: New tests.
* gcc.dg/c99-fordecl-2.c: Test diagnostic for typedef declaration
in for loop here.
* gcc.dg/pr67784-2.c, gcc.dg/pr68320.c, objc.dg/foreach-7.m: Do
not expect errors for typedef declaration in for loop.
Diffstat (limited to 'gcc/testsuite/gcc.dg/c11-fordecl-3.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/c11-fordecl-3.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/c11-fordecl-3.c b/gcc/testsuite/gcc.dg/c11-fordecl-3.c new file mode 100644 index 00000000000..28ef6294c20 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-fordecl-3.c @@ -0,0 +1,6 @@ +/* Test restrictions on the kind of declarations permitted in for loops removed + in C2X, and thus with -std=c11 -pedantic -Wno-c11-c2x-compat. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11 -pedantic -Wno-c11-c2x-compat" } */ + +#include "c99-fordecl-2.c" |