From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C3D84385840D; Sat, 18 Sep 2021 22:23:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3D84385840D From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/102401] std::bit_cast falls over, seemingly due to some invisible alignment requirements Date: Sat, 18 Sep 2021 22:23:15 +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: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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: 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: Sat, 18 Sep 2021 22:23:15 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102401 --- Comment #4 from Jonathan Wakely --- (In reply to Jakub Jelinek from comment #3) > There are things that need to be clarified, in particular value > initialization should clear even the padding bits, so supposedly > std::bit_cast of Item() if the NSDMIs would be dropped might be well defi= ned > and ok in constexpr contexts (we don't implement that currently, and don't > implement it even at runtime, we treat padding bits as always undefined), I think that's a bug. > but the above testcase has a user defined constructor and therefore no ze= ro No it doesn't. It has no constructor that is user-declared, so a default constructor is implicitly defined as defaulted. That default constructor is non-trivial (because of the default member-initializers) but it's still implicitly defi= ned. List-initialization with an empty init list means value-initialization. Sin= ce there is no user-provided default constructor, that means: "the object is zero-initialized and the semantic constraints for default-initialization are checked, and if T has a non-trivial default constructor, the object is default-initialized;" So it should be zero-initialized (which zeroes all padding) and then it sho= uld be default-initialized (which uses the implicitly-defined default construct= or, which uses the NSDMIs). So the padding bits should be initialized, no?=