From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 116370 invoked by alias); 29 Jul 2015 00:46:21 -0000 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 Received: (qmail 116334 invoked by uid 48); 29 Jul 2015 00:46:17 -0000 From: "anders.granlund.0 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/67047] GCC accepts ill-formed program with enumerator not representable in uintmax_t Date: Wed, 29 Jul 2015 00:46: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-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: anders.granlund.0 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-07/txt/msg02480.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67047 --- Comment #2 from Anders Granlund --- (In reply to Andrew Pinski from comment #1) > So the enum is an unsigned type so UINTMAX_MAX +1 is 0 as it is always > representable due to the rules of unsigned types and wrapping. Unless I > miss-understand how this is supposed to work and the wrapping rules for > unsigned types don't come into play. Incrementing enumerators never cause wrapping according to the c++ standard. This follows from this part of [dcl.enum]p5 (http://eel.is/c++draft/dcl.enum#5): "Otherwise the type of the enumerator is the same as that of the preceding enumerator unless the incremented value is not representable in that type, in which case the type is an unspecified integral type sufficient to contain the incremented value. If no such type exists, the program is ill-formed." If you test with static_assert(y != 0, ""); you can also see that no wrapping has been done. The real cause of the bug can be seen by observing that the following static assert succeeds: static_assert(sizeof (y) > sizeof(std::uintmax_t), "");