This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]