From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4EAED384646C; Fri, 5 Apr 2024 18:44:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4EAED384646C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712342647; bh=Dh5xMOpsBfF3SJ0CVr2pEpPptzBNKVfO1XECG26yQVI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dZPQ/9eZgw26QOSQwmLYGA0YK2L48aWlTyhZdJeEAFBlDK7U8SQVA3xmmYmTMrGyo TPJUUP1azhhcFC2NGC+sjvZRgz1B94YqJKPzljFTCnAy8y3ibrrjyYwp13Cfzq6Mcf EQgN8+ftTXozDOsi6qk1wtIcF9zECyffL7HMaAAc= From: "fchelnokov at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/114537] bit_cast does not work NSDMI of bitfields Date: Fri, 05 Apr 2024 18:44:06 +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: 14.0 X-Bugzilla-Keywords: FIXME X-Bugzilla-Severity: normal X-Bugzilla-Who: fchelnokov at gmail dot com X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jakub 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: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114537 --- Comment #5 from Fedor Chelnokov --- Sorry, in above example I had to use `unsigned char` type: ``` #include struct A { unsigned char a : 7; }; static_assert( std::bit_cast(std::bit_cast(A{1})).a =3D= =3D 1 ); ``` This program even after the fix in trunk, prints the same error as in the original post: :5:32: in 'constexpr' expansion of 'std::bit_cast(std::bit_cast(A{1}))' /opt/compiler-explorer/gcc-trunk-20240405/include/c++/14.0.1/bit:94:33: sor= ry, unimplemented: '__builtin_bit_cast' cannot be constant evaluated because the argument cannot be encoded 94 | return __builtin_bit_cast(_To, __from); Online demo: https://gcc.godbolt.org/z/eqrsfGEnT=