Re: [PATCH] c: Implement new -Wenum-int-mismatch warning [PR105131]

2022-05-18 Thread Pedro Alves
On 2022-05-18 00:56, Marek Polacek via Gcc-patches wrote: > +In C, an enumerated type is compatible with @code{char}, a signed > +integer type, or an unsigned integer type. However, since the choice > +of the underlying type of an enumerated type is implementation-defined, > +such mismatches may

[PATCH] c: Implement new -Wenum-int-mismatch warning [PR105131]

2022-05-17 Thread Marek Polacek via Gcc-patches
In C, an enumerated type is compatible with char, a signed integer type, or an unsigned integer type (6.7.2.2/5). Therefore this code compiles: enum E { l = -1, z = 0, g = 1 }; int foo(void); enum E foo(void) { return z; } if the underlying type of 'enum E' is 'int' (if not, we emit an