public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "paisanafc at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/112666] Missed optimization: Value initialization zero-initializes members with user-defined constructor Date: Thu, 23 Nov 2023 15:05:19 +0000 [thread overview] Message-ID: <bug-112666-4-mekzsxhykO@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-112666-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112666 --- Comment #2 from Francisco Paisana <paisanafc at gmail dot com> --- Jonathan Wakely, thanks a lot for your clarification. I finally got it. In summary, we established that: 1. if a type T (in my case C) has no user-defined ctor, it will be zero-initialized. 2. and for that T, "each non-static data member ... is zero-initialized." For others that might fall into the same trap as me, the important detail in 2 is that members are "zero-initialized" and not "value-initialized". If non-static data members were value-initialized (not the case!), then my original comment would have been true based on the clause (see https://en.cppreference.com/w/cpp/language/zero_initialization): "Zero-initialization is performed in the following situations: ... 2) As part of value-initialization sequence [...] for members of value-initialized class types that have no constructors." I wonder if there is a way to forbid the members of a class type from ever being zero-initialized in C++. In any case, we can mark this issue as solved.
next prev parent reply other threads:[~2023-11-23 15:05 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-11-22 8:58 [Bug c++/112666] New: " paisanafc at gmail dot com 2023-11-22 11:40 ` [Bug c++/112666] " redi at gcc dot gnu.org 2023-11-23 15:05 ` paisanafc at gmail dot com [this message] 2023-11-23 15:08 ` paisanafc at gmail dot com 2023-11-23 15:37 ` paisanafc at gmail dot com 2023-11-23 16:34 ` redi at gcc dot gnu.org 2023-11-23 16:35 ` sjames 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-112666-4-mekzsxhykO@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: linkBe 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).