public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108993] New: Value initialization does not occur for derived class with -Os, for gcc versions > 5
@ 2023-03-02 18:12 daniel.gotsch at bluerivertech dot com
  2023-03-02 20:42 ` [Bug c++/108993] Value initialization does not occur for derived class , " pinskia at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: daniel.gotsch at bluerivertech dot com @ 2023-03-02 18:12 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-10-12 16:34 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-02 18:12 [Bug c++/108993] New: Value initialization does not occur for derived class with -Os, for gcc versions > 5 daniel.gotsch at bluerivertech dot com
2023-03-02 20:42 ` [Bug c++/108993] Value initialization does not occur for derived class , " pinskia at gcc dot gnu.org
2023-04-19 22:17 ` panigstein at hotmail dot com
2023-04-20  8:51 ` redi at gcc dot gnu.org
2023-04-20  8:57 ` redi at gcc dot gnu.org
2023-04-20  9:08 ` redi at gcc dot gnu.org
2023-04-20 19:25 ` panigstein at hotmail dot com
2023-04-20 19:32 ` panigstein at hotmail dot com
2023-04-20 19:33 ` pinskia at gcc dot gnu.org
2023-04-21  8:29 ` redi at gcc dot gnu.org
2023-04-21  9:34 ` m.cencora at gmail dot com
2023-04-21  9:45 ` m.cencora at gmail dot com
2023-04-21 10:41 ` redi at gcc dot gnu.org
2023-04-21 10:49 ` redi at gcc dot gnu.org
2023-04-21 10:57 ` m.cencora at gmail dot com
2023-10-12 16:34 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).