aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-decl.c
diff options
context:
space:
mode:
authorManuel López-Ibáñez <manu@gcc.gnu.org>2008-10-19 13:52:10 +0000
committerManuel López-Ibáñez <manu@gcc.gnu.org>2008-10-19 13:52:10 +0000
commita7e72022ce7fbf78637fb8475e9c357f00ff120d (patch)
treea603fc519ad66ae66ae8c855cbe58febdfac8c54 /gcc/c-decl.c
parent1344d3908deca2a7c40c18aba6bebebc963ceecc (diff)
downloadgcc-a7e72022ce7fbf78637fb8475e9c357f00ff120d.zip
gcc-a7e72022ce7fbf78637fb8475e9c357f00ff120d.tar.gz
gcc-a7e72022ce7fbf78637fb8475e9c357f00ff120d.tar.bz2
re PR c/30260 (Enumeration types and enumeration constants erroneously given unsigned types)
2008-10-19 Manuel López-Ibáñez <manu@gcc.gnu.org> PR c/30260 * c-decl.c (finish_enum): Convert non-integer enumerators to enum type. (build_enumerator): Convert enumerators that fit in integer to integer type. testsuite/ * gcc.dg/pr30260.c: New. From-SVN: r141224
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r--gcc/c-decl.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 2a6dcf2..ee8e45e 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -5926,17 +5926,15 @@ 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. 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
- tem = enumtype;
- ini = convert (tem, ini);
+ integer type as an extensions. build_enumerator()
+ converts 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. Here we
+ convert the rest to the enumerator type. */
+ if (TREE_TYPE (ini) != integer_type_node)
+ ini = convert (enumtype, ini);
DECL_INITIAL (enu) = ini;
TREE_PURPOSE (pair) = DECL_NAME (enu);
@@ -6026,6 +6024,18 @@ build_enumerator (struct c_enum_contents *the_enum, tree name, tree value,
pedwarn (value_loc, OPT_pedantic,
"ISO C restricts enumerator values to range of %<int%>");
+ /* The ISO C Standard mandates enumerators to have type int, even
+ though the underlying type of an enum type is 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, we would have already warned about those that
+ don't fit. We have to do this here rather than in finish_enum
+ because this value may be used to define more enumerators. */
+ if (int_fits_type_p (value, integer_type_node))
+ value = convert (integer_type_node, value);
+
/* Set basis for default for next value. */
the_enum->enum_next_value
= build_binary_op