PR c/30260 Enumeration types and enumeration constants erroneously given unsigned types

Joseph S. Myers joseph@codesourcery.com
Thu Aug 28 23:28:00 GMT 2008


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


More information about the Gcc-patches mailing list