This is the mail archive of the
egcs-bugs@egcs.cygnus.com
mailing list for the EGCS project.
implicit copy assignment operator bug
- To: egcs-bugs@egcs.cygnus.com
- Subject: implicit copy assignment operator bug
- From: Wolfgang Sepp <wolfgang.sepp@gmx.net>
- Date: Thu, 15 Jul 1999 10:55:49 +0200 (MEST)
Hi,
GCC 2.95 (prerelease) shows still a bug in the implicit copy assignment
operator of derived classes. Consider the following program and the
corresponding output. (see also my mail to egcs-bugs of Mon, 15 Feb
1999)
Reading specs from /tmp/sepp/lib/gcc-lib/sparc-sun-solaris2.5/2.95/specs
gcc version 2.95 19990712 (prerelease)
------------------------------------------------------------------------
#include<iostream>
using namespace std;
class A
{
public:
A() {}
A( const A& )
{ cout << "called A(const A&)" << endl; }
A( A& )
{ cout << "called A( A&)" << endl; }
A& operator=( const A& )
{ cout << "called A::=(const A&)" << endl; return *this; }
A& operator=( A& )
{ cout << "called A::=( A&)" << endl; return *this; }
};
class B : public A
{
public:
B() {}
};
void foo( A& )
{
cout << "called foo( A&)" << endl;
}
void foo( const A& )
{
cout << "called foo(const A&)" << endl;
}
int main()
{
const A a0;
cout << "A(cA) : "; A a1(a0);
cout << "A(A ) : "; A a2(a1);
const B b0;
cout << "B(cB) : "; B b1(b0);
cout << "B(B ) : "; B b2(b1);
cout << "A= cA : "; a1= a0;
cout << "A= A : "; a2= a1;
cout << "B= cB : "; b1= b0;
cout << "B= B : "; b2= b1;
cout << "foo(cB): "; foo(b0);
cout << "foo(B ): "; foo(b2);
return 0;
}
------------------------------------------------------------------------
Reading specs from /tmp/sepp/lib/gcc-lib/sparc-sun-solaris2.5/2.95/specs
gcc version 2.95 19990712 (prerelease)
output:
A(cA) : called A(const A&)
A(A ) : called A( A&)
B(cB) : called A(const A&)
B(B ) : called A(const A&)
A= cA : called A::=(const A&)
A= A : called A::=( A&)
B= cB : called A::=( A&)
B= B : called A::=( A&)
foo(cB): called foo(const A&)
foo(B ): called foo( A&)
which is already better than the one of egcs-2.91.66 19990314 (1.1.2):
A(cA) : called A(const A&)
A(A ) : called A( A&)
B(cB) : called A( A&)
B(B ) : called A( A&)
A= cA : called A::=(const A&)
A= A : called A::=( A&)
B= cB : called A::=( A&)
B= B : called A::=( A&)
foo(cB): called foo(const A&)
foo(B ): called foo( A&)
but yet not fully correct. MIPSpro Compilers: Version 7.2.1.2m produced
the following output:
A(cA) : called A(const A&)
A(A ) : called A( A&)
B(cB) : called A(const A&)
B(B ) : called A(const A&)
A= cA : called A::=(const A&)
A= A : called A::=( A&)
B= cB : called A::=(const A&)
B= B : called A::=(const A&)
foo(cB): called foo(const A&)
foo(B ): called foo( A&)
bye
wolfgang
--
Sent through Global Message Exchange - http://www.gmx.net