[Bug c++/58559] Underlying type of enum is hybrid of int and unsigned
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Mar 4 11:58:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58559
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #1)
> - If you add a large enumerator so that the range of valid values is
> increased, there are no surprises:
>
> enum E { A, B, _max = -1u }; // (e < 0) and f(e) promote to unsigned now
Alternatively, give it a negative enumerator to make the underlying type
signed:
enum E { A, B, _min = INT_MIN };
This will still promote to int, but it also causes GCC to choose int as the
underlying type so there are no surprises (and no warnings for (long long)e <
0).
Based on the reasoning above (i.e. for enum E { A,B } the C++ standard requires
promotion to int irrespective of the compiler's choice of underlying type) I'm
going to close this as not a bug.
More information about the Gcc-bugs
mailing list