public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "daniel.gotsch at bluerivertech dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-108993-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2023-03-02 18:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02 18:12 daniel.gotsch at bluerivertech dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-108993-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).