This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR c/30260 Enumeration types and enumeration constants erroneously given unsigned types
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Manuel López-Ibáñez <lopezibanez at gmail dot com>
- Cc: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 27 Aug 2008 22:48:10 +0000 (UTC)
- Subject: Re: PR c/30260 Enumeration types and enumeration constants erroneously given unsigned types
- References: <6c33472e0808241058q79f20350s6076f45ae1b29530@mail.gmail.com>
On Sun, 24 Aug 2008, Manuel López-Ibáñez wrote:
> Bootstrapped and regression tested on x86_64-unknown-linux-gnu with
> --enable-languages=all,ada
>
> OK for trunk?
>
> 2008-08-24 Manuel Lopez-Ibanez <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.
>
In build_enumerator, I think you are converting to int too late.
Specifically, you should convert before enum_next_value is computed, so
that in the following test both enums get overflow correctly diagnosed
rather than just the first. (If the value is within the range of int, the
type of the initializer should not matter at all for the computation of
subsequent values.)
enum E1 { A1 = INT_MAX, B1 };
enum E2 { A2 = (unsigned) INT_MAX, B2 };
The specification (for the GNU extension of enumerators outside the range
of int) that those enumerators outside the range of int have the type of
their initializers until the enum is finished and the type of the enum
afterwards is ugly, but trying to give them the type of the enum before
it's finished would yield enums for which no consistent type can be
deduced.
--
Joseph S. Myers
joseph@codesourcery.com