Newsgroups: comp.lang.c++ Path: utzoo!utgpu!watserv1!coop3 From: coop3@watserv1.waterloo.edu (Scotte Zinn) Subject: TC1.01 Bug: temporaries not destructed??? Message-ID: <1991Feb4.202248.9670@watserv1.waterloo.edu> Organization: University of Waterloo Date: Mon, 4 Feb 91 20:22:48 GMT Lines: 61 I have the following program which, when run using TC1.01 command line compiler, calls the constructor 4 times but only calls two destructors. When compiled with G++ on UNIX, it only calls 3 constructors and 3 destructors. Is this a known bug with TC1.01??? Here is my sample program: ---Cut here--- #include class FooBar { public: FooBar(); FooBar(FooBar &x); ~FooBar(); }; FooBar::FooBar() { printf("ctor: FooBar()\n"); } FooBar::FooBar(FooBar &x) { printf("ctor: FooBar(FooBar &)\n"); } FooBar::~FooBar() { printf("dtor: FooBar()\n"); } FooBar create1() { return FooBar(); } FooBar create2() { return create1(); } void main() { FooBar x = create2(); } ---Cut Here--- I can get around this by putting temporary variables in create1() and create2(). I have also tried the TC++ version with an operator=() but the same output occured. Any comments would be appreciated. -- Scotte Zinn coop3@watserv1.uwaterloo.ca