------- Additional Comments From bangerth at dealii dot org  2004-10-16 23:34 -------
The reason, btw, why I believe that this is wrong code is that the this 
pointer of the object being constructed can escape, like here: 
------------------------------------ 
extern "C" int printf (const char *format, ...); 
 
struct A; 
 
void register_A (const A* a)   {printf ("registering   %p\n", a); } 
void deregister_A (const A* a) {printf ("deregistering %p\n", a); } 
 
struct A { 
    A ()            { register_A(this); } 
    A (const A & a) { register_A(this); } 
    ~ A ()          { deregister_A(this); } 
}; 
 
struct B { 
    A a; 
}; 
 
B b = { A () }; 
 
int main () {} 
------------------------------------ 
 
It is certainly more than just a nuisance ("missed optimization") that 
the calls to register and deregister don't match! 
 
g/x> c++ x.cc 
g/x> ./a.out  
g/x> c++ x.cc 
g/x> ./a.out  
registering   0xbfffeaa0 
deregistering 0x8049990 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |critical
            Summary|Copy constructor            |[3.3/3.4 regression] Copy
                   |optimization in aggregate   |constructor optimization in
                   |initialization              |aggregate initialization


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

Reply via email to