summaryrefslogtreecommitdiffstats
path: root/gcc/c-decl.c
diff options
context:
space:
mode:
authorspark <spark@138bc75d-0d04-0410-961f-82ee72b054a4>2007-03-12 18:31:39 +0000
committerspark <spark@138bc75d-0d04-0410-961f-82ee72b054a4>2007-03-12 18:31:39 +0000
commitaaafd660d81d50e2b1f80bed091f280c85227d65 (patch)
treef58a0ea917a7250e26da70b4e2da5c2e6db2fd99 /gcc/c-decl.c
parentcc2af1837d7bca898fa95e8eaa28d13b48c6e6fa (diff)
downloadppe42-gcc-aaafd660d81d50e2b1f80bed091f280c85227d65.tar.gz
ppe42-gcc-aaafd660d81d50e2b1f80bed091f280c85227d65.zip
ChangeLog:
2007-03-12 Seongbae Park <seongbae.park@gmail.com> * gcc/doc/invoke.texi (Wvla): New warning. gcc/ChangeLog: 2007-03-12 Seongbae Park <seongbae.park@gmail.com> * c-decl.c (warn_variable_length_array): New function. Refactored from grokdeclarator to handle warn_vla and handle unnamed array case. (grokdeclarator): Refactored VLA warning case. * c.opt (Wvla): New flag. gcc/cp/ChangeLog: 2007-03-12 Seongbae Park <seongbae.park@gmail.com> * decl.c (compute_array_index_type): New warning flag warn_vla. gcc/testsuite/ChangeLog: 2007-03-12 Seongbae Park <seongbae.park@gmail.com> * gcc.dg/wvla-1.c: New test * gcc.dg/wvla-2.c: New test * gcc.dg/wvla-3.c: New test * gcc.dg/wvla-4.c: New test * gcc.dg/wvla-5.c: New test * gcc.dg/wvla-6.c: New test * gcc.dg/wvla-7.c: New test * g++.dg/warn/Wvla-1.C: New test * g++.dg/warn/Wvla-2.C: New test * g++.dg/warn/Wvla-3.C: New test git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@122851 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r--gcc/c-decl.c67
1 files changed, 56 insertions, 11 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index fd5b065c193..eaef0a506b8 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -3891,6 +3891,61 @@ check_bitfield_type_and_width (tree *type, tree *width, const char *orig_name)
}
+
+/* Print warning about variable length array if necessary. */
+
+static void
+warn_variable_length_array (const char *name, tree size)
+{
+ int ped = !flag_isoc99 && pedantic && warn_vla != 0;
+ int const_size = TREE_CONSTANT (size);
+
+ if (ped)
+ {
+ if (const_size)
+ {
+ if (name)
+ pedwarn ("ISO C90 forbids array %qs whose size "
+ "can%'t be evaluated",
+ name);
+ else
+ pedwarn ("ISO C90 forbids array whose size "
+ "can%'t be evaluated");
+ }
+ else
+ {
+ if (name)
+ pedwarn ("ISO C90 forbids variable length array %qs",
+ name);
+ else
+ pedwarn ("ISO C90 forbids variable length array");
+ }
+ }
+ else if (warn_vla > 0)
+ {
+ if (const_size)
+ {
+ if (name)
+ warning (OPT_Wvla,
+ "the size of array %qs can"
+ "%'t be evaluated", name);
+ else
+ warning (OPT_Wvla,
+ "the size of array can %'t be evaluated");
+ }
+ else
+ {
+ if (name)
+ warning (OPT_Wvla,
+ "variable length array %qs is used",
+ name);
+ else
+ warning (OPT_Wvla,
+ "variable length array is used");
+ }
+ }
+}
+
/* Given declspecs and a declarator,
determine the name and type of the object declared
and construct a ..._DECL node for it.
@@ -4289,17 +4344,7 @@ grokdeclarator (const struct c_declarator *declarator,
nonconstant even if it is (eg) a const variable
with known value. */
size_varies = 1;
-
- if (!flag_isoc99 && pedantic)
- {
- if (TREE_CONSTANT (size))
- pedwarn ("ISO C90 forbids array %qs whose size "
- "can%'t be evaluated",
- name);
- else
- pedwarn ("ISO C90 forbids variable-size array %qs",
- name);
- }
+ warn_variable_length_array (orig_name, size);
}
if (integer_zerop (size))
OpenPOWER on IntegriCloud