From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19399 invoked by alias); 26 Nov 2012 12:43:57 -0000 Received: (qmail 19313 invoked by uid 48); 26 Nov 2012 12:43:38 -0000 From: "redi at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-11/txt/msg02391.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242 --- Comment #17 from Jonathan Wakely 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 > > enum Code { > SUCCESS = 0 > }; > > Code a = static_cast(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.