public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "panigstein at hotmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/108993] Value initialization does not occur for derived class , for gcc versions > 5
Date: Thu, 20 Apr 2023 19:32:03 +0000	[thread overview]
Message-ID: <bug-108993-4-PNKyJHnSXh@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-108993-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108993

--- Comment #7 from Pablo Anigstein <panigstein at hotmail dot com> ---
(In reply to Jonathan Wakely from comment #5)
> (In reply to Jonathan Wakely from comment #3)
> > (In reply to Pablo Anigstein from comment #2)
> > > (In reply to Andrew Pinski from comment #1)
> > > > Hmm,
> > > >  I noticed that since GCC 7 with -std=c++17, the b.x is not initialized at
> > > > all. So the question I have is there a difference between C++ standards here?
> > 
> > Derived is an aggregate in C++17, so b{} does aggregate init, not value init.
> 
> And that means its Base subobject is copy-initialized from {} which means we
> get a value-initialized object, so it's correct that b.x is not initialized
> in C++17 (which is what is shown in your godbolt link, because you didn't
> specify any -std option to override the -std=gnu++17 default).
> 
> With -std=c++14 it looks like b.x is always set to zero, if I'm reading the
> assembly output correctly (but I'm probably not).

Here is an updated example: https://godbolt.org/z/YePjhxKE4. Note that now
Derived is not an aggregate for any standard version due to the private member.
Still zero-initialization does not happen for the Base sub-object for the case
where Base has a user-provided default constructor when compiling with -O1 and
above.

  parent reply	other threads:[~2023-04-20 19:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02 18:12 [Bug c++/108993] New: Value initialization does not occur for derived class with -Os, " 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 [this message]
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-PNKyJHnSXh@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).