diff options
| author | George Burgess IV <george.burgess.iv@gmail.com> | 2018-06-28 21:36:00 +0000 |
|---|---|---|
| committer | George Burgess IV <george.burgess.iv@gmail.com> | 2018-06-28 21:36:00 +0000 |
| commit | 4d456455684caafc9eeea5743b170d794a9bd5f6 (patch) | |
| tree | 386efc546866fb36419e3c71373dd7bdb2e30923 /clang/test/Parser/gcc-for-loop-init-compatibility.c | |
| parent | 53ac1a2ed44ca7711f8872d857be0c2e4152af17 (diff) | |
| download | bcm5719-llvm-4d456455684caafc9eeea5743b170d794a9bd5f6.tar.gz bcm5719-llvm-4d456455684caafc9eeea5743b170d794a9bd5f6.zip | |
[Parse] Make -Wgcc-compat complain about for loop inits in C89
While clang allows declarations in for loop init statements in c89 and
gnu89, gcc does not. So, we should probably warn if users care about gcc
compatibility.
Differential Revision: https://reviews.llvm.org/D47840
llvm-svn: 335927
Diffstat (limited to 'clang/test/Parser/gcc-for-loop-init-compatibility.c')
| -rw-r--r-- | clang/test/Parser/gcc-for-loop-init-compatibility.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/test/Parser/gcc-for-loop-init-compatibility.c b/clang/test/Parser/gcc-for-loop-init-compatibility.c new file mode 100644 index 00000000000..dc88f083955 --- /dev/null +++ b/clang/test/Parser/gcc-for-loop-init-compatibility.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -std=c89 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=gnu89 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c99 -fsyntax-only -verify %s -DC99 + +#ifdef C99 +// expected-no-diagnostics +#endif + +void foo() { +#ifndef C99 + // expected-warning@+2{{GCC does not allow variable declarations in for loop initializers before C99}} +#endif + for (int i = 0; i < 10; i++) + ; +} |

