This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
GCC3.0-Release An extra call to the destructor
- To: gcc-bugs at gcc dot gnu dot org
- Subject: GCC3.0-Release An extra call to the destructor
- From: Kalvinder Singh <ksingh at oz dot agile dot tv>
- Date: Fri, 03 Aug 2001 11:52:00 +1000
Hi,
I have compiled a (small) sample program using VC++, and I found the
output to be different then what I get for gcc.
I am using an i686-pc-linux-gnu machine. On gcc when I specify a copy
constructor my sample program calls the destructor twice. However, if I
remove the specification of the copy constructor, my sample program
calls the destructor three times. Has anyone else seen this before???
I have also tested this on 2.96 and found that it is a problem on that
as well...:(
Any help is appreciated,
Kal.
Expected Output ( when I use VC++ or when I use -DWORKS for gcc)
The construct
There should only be two destruct calls
After Amethod in main
There should only be two destruct calls
Actual Output (GCC3.0 - i686-pc-linux-gnu)
The construct
There should only be two destruct calls
There should only be two destruct calls
After Amethod in main
There should only be two destruct calls
#include <iostream>
using namespace std;
class C
{
public:
C() {cerr << "The construct" << endl;};
#ifdef WORKS
C(const C& r) {};
#endif
~C() {cerr << "There should only be two destruct calls" << endl;};
};
class A
{
public:
A ();
virtual ~A();
virtual void Amethod (C c) = 0;
private:
A(const A &right);
A & operator=(const A &right);
};
inline A::~A()
{
}
A::A ()
{
}
class B : public A
{
public:
B ();
virtual ~B();
void Amethod (C c);
private:
B(const B &right);
B & operator=(const B &right);
};
B::B ()
{
}
B::~B()
{
}
void B::Amethod (C c)
{
}
int main(int argc, char *argv[])
{
A* xxxx = new B;
C c;
xxxx->Amethod(c);
cerr <<"After Amethod in main " << endl;
return 1;
}