[Bug c++/61568] New: unscoped enums different types differ from __underlying_type
myriachan at cox dot net
gcc-bugzilla@gcc.gnu.org
Fri Jun 20 05:19:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61568
Bug ID: 61568
Summary: unscoped enums different types differ from
__underlying_type
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: myriachan at cox dot net
If you have an unscoped, unfixed-type enum whose members exist solely within
[0...INT_MAX], the enum type is considered "signed int", but the
"__underlying_type" intrinsic operator returns "unsigned int". As a result,
the following paradoxical C++ code compiles when it should not. (This also
occurs if you use type_traits and std::underlying type instead of the intrinsic
directly.)
This may be a duplicate of bug 58559.
template <typename T> struct type_is_unsigned_int { static const bool value =
false; };
template <> struct type_is_unsigned_int<unsigned int> { static const bool value
= true; };
enum unscoped_unfixed_size_enum {
some_enum_name = 0,
};
static_assert(
static_cast<unscoped_unfixed_size_enum>(-1) <
static_cast<unscoped_unfixed_size_enum>(0),
"This assert doesn't fire, indicating that the enum is signed.");
static_assert(
static_cast<__underlying_type(unscoped_unfixed_size_enum)>(-1) >
static_cast<__underlying_type(unscoped_unfixed_size_enum)>(0),
"But neither does this one! It's inconsistent.");
static_assert(
type_is_unsigned_int<__underlying_type(unscoped_unfixed_size_enum)>::value,
"The exact type in the implementation is, in fact, \"unsigned int\".");
More information about the Gcc-bugs
mailing list