public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/61568] New: unscoped enums different types differ from __underlying_type
@ 2014-06-20  5:19 myriachan at cox dot net
  2014-06-20 17:14 ` [Bug c++/61568] " harald at gigawatt dot nl
  2014-06-20 19:31 ` myriachan at cox dot net
  0 siblings, 2 replies; 3+ messages in thread
From: myriachan at cox dot net @ 2014-06-20  5:19 UTC (permalink / raw)
  To: gcc-bugs

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\".");


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-06-20 19:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-20  5:19 [Bug c++/61568] New: unscoped enums different types differ from __underlying_type myriachan at cox dot net
2014-06-20 17:14 ` [Bug c++/61568] " harald at gigawatt dot nl
2014-06-20 19:31 ` myriachan at cox dot net

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).