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++/16982] wrong copy ctor called


------- Additional Comments From bangerth at dealii dot org  2004-08-11 18:12 -------
Here's a testcase that's slightly simpler to understand: 
-------------------- 
#include <iostream> 
extern "C" void abort (); 
 
#define WHEREAMI std::cout << __PRETTY_FUNCTION__ << std::endl 
 
struct base { 
  base () {WHEREAMI;} 
   
  base (base const&) { 
    WHEREAMI; 
    abort (); 
  } 
}; 
 
struct derived : base { 
  derived () { WHEREAMI; } 
  derived (derived const&) : base () { WHEREAMI; } 
}; 
 
 
struct s { 
  operator derived () { 
    WHEREAMI; 
    return derived (); 
  } 
}; 
 
int main () { 
  s s; 
  base const& b (s); 
} 
------------------------------- 
 
With 3.4, we get this output: 
 
g/x> ./a.out  
s::operator derived() 
base::base() 
derived::derived() 
base::base(const base&) 
Aborted 
 
In other words, the abort happens when the temporary returned from 
the call to s::operator derived is casted to a reference of the base 
class. I am pretty sure the compiler is allowed to do so, but don't 
right now have the correct section of the standard available. 
 
In any case, the question may be moot, since with mainline we get this: 
 
g/x> /home/bangerth/bin/gcc-3.5-pre/bin/c++ x.cc 
g/x> ./a.out  
s::operator derived() 
base::base() 
derived::derived() 
 
I.e. there is no abort and the program does what you expect. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |3.5.0


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


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