This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[daily C++ bug-report] Object of Empty Class Destroyed Twice
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: [daily C++ bug-report] Object of Empty Class Destroyed Twice
- From: Gabriel Dos_Reis <Gabriel dot Dos_Reis at sophia dot inria dot fr>
- Date: 29 Apr 1999 07:47:47 +0200
- Organization: I.N.R.I.A Sophia-Antipolis (France)
The following program demonstrates a nasty bug (in fact a regression)
we've got since (at least) egcs-1.1.2 and present in current CVS. It
makes EGCS/g++ unusable in certain circumstances (objects that keep
trace of themselves, in debugging mode for ex.). As far as I can tell
the bug seems to be plateform-independent and optimization-level
independent. It doesn't show up in case of non-empty classes.
// --- cut here ---
#include <iostream>
struct A {
A() { std::cout << "A::A()\n"; }
A(const A&) { std::cout << "A::A(const A&)\n"; }
~A() { std::cout << "A::~A()\n"; }
};
struct B {
A f() const { return A(); }
};
int main()
{
B b;
A a( b.f ());
}
// -- cut here --
When compiled with egcs-2.93.20 it outputs:
A::A()
A::~A()
A::~A()
A related bug was reported some days ago:
http://egcs.cygnus.com/ml/egcs-bugs/1999-03/msg00558.html
-- Gaby