public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15172] New: Copy constructor optimization in aggregate initialization
@ 2004-04-27 17:28 michael dot spencer at ubs dot com
  2004-04-27 17:49 ` [Bug c++/15172] " pinskia at gcc dot gnu dot org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: michael dot spencer at ubs dot com @ 2004-04-27 17:28 UTC (permalink / raw)
  To: gcc-bugs

gcc configured with: --with-gnu-as --with-gnu-ld

A class member of an aggregate appears to be initialized in temporary
storage then byte-copied to its final location, as this code shows:

  int printf (const char *format, ...);

  struct A {
    A * _this;
    A () : _this (this)
    { printf ("A ()          : this = %p, _this = %p\n", this, _this); }
    ~ A ()
    { printf ("~ A ()        : this = %p, _this = %p\n", this, _this); }
    void print ()
    { printf ("print ()      : this = %p, _this = %p\n", this, _this); }

    A (const A & a) : _this (this)
    { printf ("A (const A &) : this = %p, _this = %p\n", this, _this); }
  };

  struct B {
    A a;
  };

  B b = { A () };

  int main () {
    b.a.print ();
  }

When run, the program produces:

  A ()          : this = ffbeae00, _this = ffbeae00
  print ()      : this = 20e2c, _this = ffbeae00
  ~ A ()        : this = 20e2c, _this = ffbeae00

I expected to see the "_this" member compare with "this" in all cases.
In gcc 2.95 this is true.

12.6.1p2 of the Standard states that class members of aggregates are
copy-initialized in this context.

-- 
           Summary: Copy constructor optimization in aggregate
                    initialization
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: michael dot spencer at ubs dot com
                CC: gcc-bugs at gcc dot gnu dot org,michael dot spencer at
                    ubs dot com
 GCC build triplet: sparc-sun-solaris2.8
  GCC host triplet: sparc-sun-solaris2.8
GCC target triplet: sparc-sun-solaris2.8


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


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

end of thread, other threads:[~2004-11-01  0:14 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-27 17:28 [Bug c++/15172] New: Copy constructor optimization in aggregate initialization michael dot spencer at ubs dot com
2004-04-27 17:49 ` [Bug c++/15172] " pinskia at gcc dot gnu dot org
2004-04-27 18:58 ` michael dot spencer at ubs dot com
2004-04-28 11:28 ` giovannibajo at libero dot it
2004-06-03 22:57 ` pinskia at gcc dot gnu dot org
2004-10-16 22:57 ` acehreli at yahoo dot com
2004-10-16 23:28 ` bangerth at dealii dot org
2004-10-16 23:34 ` [Bug c++/15172] [3.3/3.4 regression] " bangerth at dealii dot org
2004-10-17  1:01 ` acehreli at yahoo dot com
2004-10-17 11:21 ` giovannibajo at libero dot it
2004-10-26  8:31 ` ebotcazou at gcc dot gnu dot org
2004-10-27 17:59 ` ebotcazou at gcc dot gnu dot org
2004-10-29 15:15 ` TazForEver at dlfp dot org
2004-10-31  1:58 ` mmitchel at gcc dot gnu dot org
2004-10-31 19:02 ` mmitchel at gcc dot gnu dot org
2004-11-01  0:02 ` cvs-commit at gcc dot gnu dot org
2004-11-01  0:07 ` cvs-commit at gcc dot gnu dot org
2004-11-01  0:14 ` mmitchel at gcc dot gnu dot 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).