[Bug c++/15172] New: Copy constructor optimization in aggregate initialization
michael dot spencer at ubs dot com
gcc-bugzilla@gcc.gnu.org
Tue Apr 27 17:28:00 GMT 2004
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
More information about the Gcc-bugs
mailing list