[Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Nov 26 12:43:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242
--- Comment #17 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-11-26 12:43:37 UTC ---
(In reply to comment #15)
> we *error* out anyway, isn't that we are only emitting a warning and only when
> we are assigning the SHRT_MAX + 1.
But isn't the error because there's no implicit conversion from a scoped
enunmeration type to short? That's just invalid.
And my point is that the narrowing warning is correct, because 'a' is not a
constant expression and its value could be out of the range
[SHRT_MIN,SHRT_MAX].
(In reply to comment #16)
> And to further clarify wrt your specific Comment 11, Jon, for:
>
> #include <limits.h>
>
> enum Code {
> SUCCESS = 0
> };
>
> Code a = static_cast<Code>(SHRT_MAX + 1);
>
> short r[] = {a};
>
> we currently don't warn.
Because the values of that unscoped enum type are [0,1] which always fit in
short. With a scoped enumeration type the underlying type is fixed so the
values of the enumeration type are the values of the underlying type which are
[INT_MIN,INT_MAX]. But this seems unrelated to using scoped enums as bitfields
anyway.
More information about the Gcc-bugs
mailing list