public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "crowl at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/33916] Default constructor fails to initialize array members
Date: Wed, 31 Oct 2007 20:08:00 -0000	[thread overview]
Message-ID: <20071031200813.8496.qmail@sourceware.org> (raw)
In-Reply-To: <bug-33916-11211@http.gcc.gnu.org/bugzilla/>



------- Comment #1 from crowl at google dot com  2007-10-31 20:08 -------
The wording in the C++ standard working paper is as follows:

8.5 Initializers [dcl.init]

-8- An object whose initializer is an empty set of parentheses, i.e.,
   (), shall be value-initialized.

Therefore, in <<< Stats my_stats = Stats(); >>>, the temporary object
is value-initialized and then my_stats is copy-constructed.

-5- To value-initialize an object of type T means:
   -- if T is a non-union class type without a user-provided
      constructor, then every non-static data member and base-class
      component of T is value-initialized;93)

   93) Value-initialization for such a class object may be
       implemented by zero-initializing the object and then calling
       the default constructor.

   -- if T is an array type, then each element is value-initialized;

   -- otherwise, the object is zero-initialized

Therefore, the temporary should be zero-initialized and the resulting
copy should copy zeros.  So, I conclude that gcc 4.2.1 is in error.
(I suspect the compiler already eliminates the copy.)

I suspect the problem arose in someone thinking that the zero
initialization in front of a call to a default constructor was
redundant.  Alas, it is not.  It is redundant only if the constructor
initializes all fields, which is generally unknowable, though the
compiler could determine so for many types and constructors.


-- 

crowl at google dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |crowl at google dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33916


  reply	other threads:[~2007-10-31 20:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-26 21:06 [Bug c++/33916] New: " mec at google dot com
2007-10-31 20:08 ` crowl at google dot com [this message]
2007-11-01  2:17 ` [Bug c++/33916] " gdr at gcc dot gnu dot org
2007-12-11  0:04 ` [Bug c++/33916] [4.2/4.3 Regression] " janis at gcc dot gnu dot org
2007-12-11  0:17 ` pinskia at gcc dot gnu dot org
2007-12-12 20:55 ` mmitchel at gcc dot gnu dot org
2008-01-02 23:49 ` mmitchel at gcc dot gnu dot org
2008-01-07 19:21 ` mmitchel at gcc dot gnu dot org
2008-01-07 19:47 ` crowl at google dot com
2008-01-22 21:23 ` steven at gcc dot gnu dot org
2008-01-25 16:54 ` rguenth at gcc dot gnu dot org
2008-02-01 17:01 ` jsm28 at gcc dot gnu dot org
2008-02-04  3:30 ` jason at gcc dot gnu dot org
2008-02-04 12:15 ` [Bug c++/33916] [4.2 " rguenth at gcc dot gnu dot org
2008-02-12  6:39 ` jason at gcc dot gnu dot org
2008-02-12  6:42 ` jason at gcc dot gnu dot 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=20071031200813.8496.qmail@sourceware.org \
    --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).