GCC implements -Wvla as "warn on every VLA" (this is useful to find every VLA,
for example, if they are forbidden by coding guidelines). Currently Clang
implements -Wvla as "warn on VLA when it is an extension".
The attached patch makes our behavior match GCC. The existing vla extwarn is
moved under -Wvla-extension and is still included into -Wgnu.
This fixes PR5953.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173286
91177308-0d34-0410-b5e6-
96231b3b80d8
def VectorConversion : DiagGroup<"vector-conversion">; // clang specific
def VexingParse : DiagGroup<"vexing-parse">;
def VLA : DiagGroup<"vla">;
+def VLAExtension : DiagGroup<"vla-extension">;
def VolatileRegisterVar : DiagGroup<"volatile-register-var">;
def Visibility : DiagGroup<"visibility">;
def ZeroLengthArray : DiagGroup<"zero-length-array">;
def C99 : DiagGroup<"c99-extensions">;
// A warning group for warnings about GCC extensions.
-def GNU : DiagGroup<"gnu", [GNUDesignator, VLA, ZeroLengthArray]>;
+def GNU : DiagGroup<"gnu", [GNUDesignator, VLAExtension, ZeroLengthArray]>;
// A warning group for warnings about code that clang accepts but gcc doesn't.
def GccCompat : DiagGroup<"gcc-compat">;
// C99 variable-length arrays
def ext_vla : Extension<"variable length arrays are a C99 feature">,
- InGroup<VLA>;
+ InGroup<VLAExtension>;
+def warn_vla_used : 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">;
: diag::ext_c99_array_usage) << ASM;
}
+ if (T->isVariableArrayType()) {
+ // Warn about VLAs for -Wvla.
+ Diag(Loc, diag::warn_vla_used);
+ }
+
return T;
}
--- /dev/null
+// RUN: %clang_cc1 -std=c99 -fsyntax-only -verify -Wvla %s
+// RUN: %clang_cc1 -std=c89 -fsyntax-only -verify -Wvla %s
+
+void test1(int n) {
+ int v[n]; // expected-warning {{variable length array used}}
+}
+
+void test2(int n, int v[n]) { // expected-warning {{variable length array used}}
+}
+
+void test3(int n, int v[n]); // expected-warning {{variable length array used}}
+
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wvla %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wvla-extension %s
struct StillPOD {
StillPOD() = default;
};
-// RUN: %clang_cc1 -fsyntax-only -verify -Wvla %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wvla-extension %s
struct NonPOD {
NonPOD();
};
--- /dev/null
+// RUN: %clang_cc1 -fsyntax-only -verify -Wvla %s
+
+void test1(int n) {
+ int v[n]; // expected-warning {{variable length array used}}
+}
+
+void test2(int n, int v[n]) { // expected-warning {{variable length array used}}
+}
+
+void test3(int n, int v[n]); // expected-warning {{variable length array used}}
+
+template<typename T>
+void test4(int n) {
+ int v[n]; // expected-warning {{variable length array used}}
+}
+
+template<typename T>
+void test5(int n, int v[n]) { // expected-warning {{variable length array used}}
+}
+
+template<typename T>
+void test6(int n, int v[n]); // expected-warning {{variable length array used}}
+
+template<typename T>
+void test7(int n, T v[n]) { // expected-warning {{variable length array used}}
+}
+