From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 248CE3858D37; Thu, 2 Mar 2023 18:12:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 248CE3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677780757; bh=KpK/+Hcy0wSb2W3yBQoxiXHEJ6IBjr7ivKgpd11S8js=; h=From:To:Subject:Date:From; b=W4GxrAi6tkuKLBZH/3O8E3x99Xqd5leWq5eeLAE1w+yhhLzmiDkRRyfSOTuIgbviE ybGGw4yduqROewcjFrTKbFRSZAt6mu0XIkpQR7MBQbReUmjhrNIpd7utn3oTT1TOUU aeCSeTkTeqq3qdbPdawlF5WpR1CRAtQxq0Pas4sI= From: "daniel.gotsch at bluerivertech dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108993] New: Value initialization does not occur for derived class with -Os, for gcc versions > 5 Date: Thu, 02 Mar 2023 18:12:36 +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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: daniel.gotsch at bluerivertech 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: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108993 Bug ID: 108993 Summary: Value initialization does not occur for derived class with -Os, for gcc versions > 5 Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: daniel.gotsch at bluerivertech dot com Target Milestone: --- Minimal example: #include struct Base { Base() {} // not a default constructor double x; }; struct Derived : public Base { Derived() =3D default; // default constructor should lead to zero-initialization }; int main () { Base a{};=20 std::cout << a.x; // Could be any value Derived b{}; std::cout << b.x; // Should be set 0 but isn't set 0 when compiled with= -Os flag } see compiler output https://godbolt.org/z/Ecr1K9cMM The class Derived has a default constructor which satisfies (2) of value-initalization meaning the object should be zero-initialized. see https://en.cppreference.com/w/cpp/language/value_initialization Zero-initialization should zero-out the base class too, see https://en.cppreference.com/w/cpp/language/zero_initialization=