summaryrefslogtreecommitdiffstats
path: root/gcc/c-decl.c
diff options
context:
space:
mode:
authormanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>2008-08-13 10:19:03 +0000
committermanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>2008-08-13 10:19:03 +0000
commite8fc0d3480bf8f266db2caa965af50776e270ec9 (patch)
tree1628ba21d162d8c904b22105327717febc42c784 /gcc/c-decl.c
parent2725970784399fb8efb1c946472340c2de074f45 (diff)
downloadppe42-gcc-e8fc0d3480bf8f266db2caa965af50776e270ec9.tar.gz
ppe42-gcc-e8fc0d3480bf8f266db2caa965af50776e270ec9.zip
2008-08-13 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c/15236 * diagnostic.c (pedwarn_at): New. * toplev.h (pedwarn_at): Declare. * c-tree.h (build_enumerator): Update declaration. * c-decl.c (finish_enum): Update comment. (build_enumerator): Take a location parameter. Give a pedwarn but do not perform any conversion. * c-parser.c (c_parser_enum_specifier): Set correct location for enumerator. testsuite/ * gcc.dg/pr15236.c: New. * gcc.dg/torture/pr25183.c: Update. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@139050 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r--gcc/c-decl.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index e30defdd0e8..e55e809b1f4 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -5877,11 +5877,13 @@ finish_enum (tree enumtype, tree values, tree attributes)
/* The ISO C Standard mandates enumerators to have type int,
even though the underlying type of an enum type is
- unspecified. Here we convert any enumerators that fit in
- an int to type int, to avoid promotions to unsigned types
- when comparing integers with enumerators that fit in the
- int range. When -pedantic is given, build_enumerator()
- would have already taken care of those that don't fit. */
+ unspecified. However, GCC allows enumerators of any
+ integer type as an extensions. Here we convert any
+ enumerators that fit in an int to type int, to avoid
+ promotions to unsigned types when comparing integers with
+ enumerators that fit in the int range. When -pedantic is
+ given, build_enumerator() would have already warned about
+ those that don't fit. */
if (int_fits_type_p (ini, integer_type_node))
tem = integer_type_node;
else
@@ -5933,7 +5935,8 @@ finish_enum (tree enumtype, tree values, tree attributes)
Assignment of sequential values by default is handled here. */
tree
-build_enumerator (struct c_enum_contents *the_enum, tree name, tree value)
+build_enumerator (struct c_enum_contents *the_enum, tree name, tree value,
+ location_t value_loc)
{
tree decl, type;
@@ -5967,14 +5970,13 @@ build_enumerator (struct c_enum_contents *the_enum, tree name, tree value)
if (the_enum->enum_overflow)
error ("overflow in enumeration values");
}
-
- if (pedantic && !int_fits_type_p (value, integer_type_node))
- {
- pedwarn (OPT_pedantic, "ISO C restricts enumerator values to range of %<int%>");
- /* XXX This causes -pedantic to change the meaning of the program.
- Remove? -zw 2004-03-15 */
- value = convert (integer_type_node, value);
- }
+ /* Even though the underlying type of an enum is unspecified, the
+ type of enumeration constants is explicitly defined as int
+ (6.4.4.3/2 in the C99 Standard). GCC allows any integer type as
+ an extension. */
+ else if (!int_fits_type_p (value, integer_type_node))
+ pedwarn_at (value_loc, OPT_pedantic,
+ "ISO C restricts enumerator values to range of %<int%>");
/* Set basis for default for next value. */
the_enum->enum_next_value = build_binary_op (PLUS_EXPR, value,
OpenPOWER on IntegriCloud