public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields Date: Mon, 26 Nov 2012 12:43:00 -0000 [thread overview] Message-ID: <bug-51242-4-JQnVc118Ec@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-51242-4@http.gcc.gnu.org/bugzilla/> 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.
next prev parent reply other threads:[~2012-11-26 12:43 UTC|newest] Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-11-20 19:55 [Bug c++/51242] New: " volodya at netfolder dot ru 2011-11-20 20:30 ` [Bug c++/51242] [C++11] " redi at gcc dot gnu.org 2012-11-18 18:05 ` redi at gcc dot gnu.org 2012-11-19 5:47 ` volodya at netfolder dot ru 2012-11-19 7:26 ` daniel.kruegler at googlemail dot com 2012-11-19 7:56 ` volodya at netfolder dot ru 2012-11-19 11:47 ` redi at gcc dot gnu.org 2012-11-19 11:52 ` redi at gcc dot gnu.org 2012-11-19 16:31 ` volodya at netfolder dot ru 2012-11-26 11:26 ` paolo.carlini at oracle dot com 2012-11-26 11:32 ` paolo.carlini at oracle dot com 2012-11-26 11:37 ` paolo.carlini at oracle dot com 2012-11-26 11:47 ` redi at gcc dot gnu.org 2012-11-26 11:51 ` redi at gcc dot gnu.org 2012-11-26 12:00 ` paolo.carlini at oracle dot com 2012-11-26 12:05 ` paolo.carlini at oracle dot com 2012-11-26 12:12 ` paolo.carlini at oracle dot com 2012-11-26 12:23 ` paolo.carlini at oracle dot com 2012-11-26 12:43 ` redi at gcc dot gnu.org [this message] 2012-11-26 12:50 ` paolo.carlini at oracle dot com 2012-11-26 12:56 ` redi at gcc dot gnu.org 2012-11-26 13:00 ` paolo.carlini at oracle dot com 2012-11-26 13:28 ` paolo.carlini at oracle dot com 2012-11-26 13:39 ` paolo.carlini at oracle dot com 2012-11-26 14:00 ` paolo.carlini at oracle dot com 2012-11-26 14:40 ` redi at gcc dot gnu.org 2013-02-16 1:07 ` paolo at gcc dot gnu.org 2013-02-27 10:33 ` paolo.carlini at oracle dot com 2020-11-08 18:06 ` barry.revzin at gmail dot com 2020-11-09 10:01 ` redi at gcc dot gnu.org
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-51242-4-JQnVc118Ec@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).