From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B7F4B385E00A; Thu, 23 Nov 2023 15:05:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B7F4B385E00A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700751920; bh=SoGDueELkuYc3i8nzAAS1aVAh2E4aSBGxCkOC6hUaEg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=xgxIrbERIeEQKAkz1UisvU96e/7/5nTLUtukMt8M6eAyfinNLWOiIKRkAHoLBggGr NAMYuSdL8U3Ic9x3OsgkoKZYNxyFOOZThylVCmP4A/hhEvfuHnedjXenz7YNNxuL4F 1n+OfWoSBLUe1a2XMywqd3oTkycW3+g6xldlH9y4= From: "paisanafc at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/112666] Missed optimization: Value initialization zero-initializes members with user-defined constructor Date: Thu, 23 Nov 2023 15:05:19 +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: 11.4.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: paisanafc 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: 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=3D112666 --- Comment #2 from Francisco Paisana --- Jonathan Wakely, thanks a lot for your clarification. I finally got it.=20 In summary, we established that: 1. if a type T (in my case C) has no user-defined ctor, it will be zero-initialized. 2. and for that T, "each non-static data member ... is zero-initialized." For others that might fall into the same trap as me, the important detail i= n 2 is that members are "zero-initialized" and not "value-initialized". If non-static data members were value-initialized (not the case!), then my original comment would have been true based on the clause (see https://en.cppreference.com/w/cpp/language/zero_initialization): "Zero-initialization is performed in the following situations: ... 2) As part of value-initialization sequence [...] for members of value-initialized class types that have no constructors." I wonder if there is a way to forbid the members of a class type from ever being zero-initialized in C++. In any case, we can mark this issue as solved.=