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]

[daily C++ bug-report] Object of Empty Class Destroyed Twice



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

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