From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BEC4D384C005; Wed, 17 Mar 2021 20:46:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEC4D384C005 From: "hanicka at hanicka dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99637] New: bit_cast doesn't work with padding bits and it should Date: Wed, 17 Mar 2021 20:46:44 +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: X-Bugzilla-Severity: normal X-Bugzilla-Who: hanicka at hanicka dot net 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 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: Wed, 17 Mar 2021 20:46:44 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99637 Bug ID: 99637 Summary: bit_cast doesn't work with padding bits and it should Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: hanicka at hanicka dot net Target Milestone: --- Standard states in https://eel.is/c++draft/bit.cast#2 "Padding bits of the result are unspecified." Current trunk GCC (11.0.1 20210316) gives error in presence of padding bits: https://compiler-explorer.com/z/MhKMb5 ``` struct my_field { // change size to 64 and it will work unsigned long long a : 63; }; constexpr unsigned long long get_value(const auto & val) noexcept { static_assert(sizeof(val) =3D=3D sizeof(unsigned long long)); return __builtin_bit_cast(unsigned long long, val); } constexpr auto f =3D my_field{0}; constexpr auto v =3D get_value(f); ``` this is the error message GCC gives, but this shouldn't be a hard error ``` :14:29: in 'constexpr' expansion of 'get_value(f)' :10:31: error: '__builtin_bit_cast' accessing uninitialized byte at offset 7 10 | return __builtin_bit_cast(unsigned long long, val); ```=