This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/15172] Copy constructor optimization in aggregate initialization


------- Additional Comments From bangerth at dealii dot org  2004-10-16 23:28 -------
Something is definitely wrong with this testcase. I think that storing and 
printing the _this pointer is only obstructing the view of the problem 
somehow, so consider this example here: 
-------------------- 
int printf (const char *format, ...); 
 
struct A { 
    A () 
      { printf ("A::A ()          : this = %p\n", this); } 
       
    A (const A & a) 
      { printf ("A::A (const A&)  : this = %p\n", this); } 
 
    ~ A () 
      { printf ("A::~A ()         : this = %p\n", this); } 
       
    void print () 
      { printf ("print ()         : this = %p\n", this); } 
}; 
 
struct B { 
    A a; 
}; 
 
B b = { A () }; 
 
int main () { 
  b.a.print (); 
} 
------------------------ 
 
I think we all agree that we always have to have matching calls to 
(copy) constructors and destructors for a this pointer, but we really 
get this here: 
 
g/x> c++ x.cc 
g/x> ./a.out  
A::A ()          : this = 0xbfffeaa0 
print ()         : this = 0x80499c8 
A::~A ()         : this = 0x80499c8 
 
I don't think this can ever be right. 
 
This used to work in gcc2.95, but is broken between 3.2 and 3.4. It works 
fine in mainline again, though, so this is a 3.3/3.4 branch regression 
only. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|missed-optimization         |wrong-code
      Known to fail|                            |3.2.3 3.3.5 3.4.2
      Known to work|                            |2.95 4.0.0
   Last reconfirmed|2004-06-03 22:57:00         |2004-10-16 23:28:23
               date|                            |
   Target Milestone|---                         |3.4.3


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]