From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A0D3938460A3; Thu, 6 Aug 2020 13:36:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0D3938460A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596721000; bh=QY2c9c8tEqYZJDsZ54ggYys/c2X7+XoxvwMhwIty3Ro=; h=From:To:Subject:Date:From; b=HESw3r9wJNI3pL7dlOQuk4xj4suxQRkED5ZSUqdHZ7hBJqUOG5Mhq2AhtoM/YT96k IQpS2jgOQ0J4KTrNNtolGZJNz9oW0EAn0Mnkm7r8CeCyZdEUloREuiqTLsago4Z/nm a4Vw7nYj0ggDU+UHYLvpJFqqAWakA0uqk4ocmXzM= From: "fw at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/96496] New: Conversion to enum with underlying type bool produces wrong result Date: Thu, 06 Aug 2020 13:36:40 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: fw at gcc dot gnu.org 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: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Aug 2020 13:36:40 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96496 Bug ID: 96496 Summary: Conversion to enum with underlying type bool produces wrong result Product: gcc Version: 11.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: fw at gcc dot gnu.org Target Milestone: --- enum E : bool { One, Two }; int f1 (int x) { return (E) x; } The conversion must first be to type bool, according to: =E2=80=9CIf the enumeration type has a fixed underlying type, the value is = first converted to that type by integral conversion, if necessary, and then to the enumeration type.=E2=80=9D And that must produce a comparison against zero: =E2=80=9CA zero value, null pointer value, or null member pointer value is = converted to false; any other value is converted to true.=E2=80=9D Currently, GCC performs a bit mask (at -O2): _Z2f1i: movl %edi, %eax andl $1, %eax ret=