https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108993
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 <iostream> struct Base { Base() {} // not a default constructor double x; }; struct Derived : public Base { Derived() = default; // default constructor should lead to zero-initialization }; int main () { Base a{}; 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