[cfe-commits] [PATCH] Make -Wvla warn in C99 mode (impact on -Wgnu?)
Eli Friedman
eli.friedman at gmail.com
Mon Apr 11 17:14:02 PDT 2011
Patch attached; I would just commit, but it changes the behavior of
-Wgnu in a way I'm not sure is correct. Can someone explain the
intent for -Wgnu and why it includes -Wvla? (The svn history only
says it's supposed to "Control warnings about GNU extensions".)
-Eli
-------------- next part --------------
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td (revision 129282)
+++ include/clang/Basic/DiagnosticSemaKinds.td (working copy)
@@ -37,6 +37,9 @@
def ext_vla : Extension<
"variable length arrays are a C99 feature, accepted as an extension">,
InGroup<VLA>;
+def warn_vla : Warning<
+ "variable length array used">,
+ InGroup<VLA>, DefaultIgnore;
def err_vla_non_pod : Error<"variable length array of non-POD element type %0">;
def err_vla_in_sfinae : Error<
"variable length array cannot be formed during template argument deduction">;
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp (revision 129282)
+++ lib/Sema/SemaType.cpp (working copy)
@@ -1221,8 +1221,8 @@
T = Context.getConstantArrayType(T, ConstVal, ASM, Quals);
}
- // If this is not C99, extwarn about VLA's and C99 array size modifiers.
if (!getLangOptions().C99) {
+ // If this is not C99, extwarn about VLA's and C99 array size modifiers.
if (T->isVariableArrayType()) {
// Prohibit the use of non-POD types in VLAs.
if (!T->isDependentType() &&
@@ -1243,6 +1243,10 @@
Diag(Loc,
getLangOptions().CPlusPlus? diag::err_c99_array_usage_cxx
: diag::ext_c99_array_usage);
+ } else {
+ // Warn about VLAs if the user uses -Wvla.
+ if (T->isVariableArrayType())
+ Diag(Loc, diag::warn_vla);
}
return T;
More information about the cfe-commits
mailing list