public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "myriachan at cox dot net" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/61568] New: unscoped enums different types differ from __underlying_type Date: Fri, 20 Jun 2014 05:19:00 -0000 [thread overview] Message-ID: <bug-61568-4@http.gcc.gnu.org/bugzilla/> (raw) 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\".");
next reply other threads:[~2014-06-20 5:19 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-06-20 5:19 myriachan at cox dot net [this message] 2014-06-20 17:14 ` [Bug c++/61568] " harald at gigawatt dot nl 2014-06-20 19:31 ` myriachan at cox dot net
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-61568-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).