[PATCH] D47840: Make -Wgcc-compat complain about declarations in for loop init statements
George Burgess IV via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 28 14:40:45 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL335927: [Parse] Make -Wgcc-compat complain about for loop inits in C89 (authored by gbiv, committed by ).
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D47840?vs=150167&id=153403#toc
Repository:
rL LLVM
https://reviews.llvm.org/D47840
Files:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/test/Parser/gcc-for-loop-init-compatibility.c
Index: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
===================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
@@ -173,6 +173,9 @@
def warn_gcc_attribute_location : Warning<
"GCC does not allow an attribute in this position on a function declaration">,
InGroup<GccCompat>;
+def warn_gcc_variable_decl_in_for_loop : Warning<
+ "GCC does not allow variable declarations in for loop initializers before "
+ "C99">, InGroup<GccCompat>;
def warn_attribute_no_decl : Warning<
"attribute %0 ignored, because it is not attached to a declaration">,
InGroup<IgnoredAttributes>;
Index: cfe/trunk/test/Parser/gcc-for-loop-init-compatibility.c
===================================================================
--- cfe/trunk/test/Parser/gcc-for-loop-init-compatibility.c
+++ cfe/trunk/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 at +2{{GCC does not allow variable declarations in for loop initializers before C99}}
+#endif
+ for (int i = 0; i < 10; i++)
+ ;
+}
Index: cfe/trunk/lib/Parse/ParseStmt.cpp
===================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp
+++ cfe/trunk/lib/Parse/ParseStmt.cpp
@@ -1624,8 +1624,10 @@
ParenBraceBracketBalancer BalancerRAIIObj(*this);
// Parse declaration, which eats the ';'.
- if (!C99orCXXorObjC) // Use of C99-style for loops in C90 mode?
+ if (!C99orCXXorObjC) { // Use of C99-style for loops in C90 mode?
Diag(Tok, diag::ext_c99_variable_decl_in_for_loop);
+ Diag(Tok, diag::warn_gcc_variable_decl_in_for_loop);
+ }
// In C++0x, "for (T NS:a" might not be a typo for ::
bool MightBeForRangeStmt = getLangOpts().CPlusPlus;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47840.153403.patch
Type: text/x-patch
Size: 2093 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180628/811ce18d/attachment.bin>
More information about the cfe-commits
mailing list