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]

gcc 2.95.2 fails to destroy objects created by 'throw'


Platforms:   ALL? (Sparc32 and x86 tested)

Description: gcc 2.95.2 (as found on any GNU mirror) fails to call
             the destructor for objects created by throw (or any
             copies of these objects).

Comments:    It looks like SuSe, RedHat and Debian have patches to
             fix this that are not part of the main-branch?

Attached is some code to demonstrate this. If you alter the catch
like to catch an object not a reference, you can see that isn't
destroyed either.

I have patches to correct this that I pulled out of the Debian diffs,
they are somewhat extensive and probably impact many other things.
Let me know if you want these.



-cw






#include <stdio.h>
#include <string.h>

int		ref = 0;

class exception {
private:
		
public:
	exception(char* m)
	{
		ref++;
	}

	~exception()
	{
		ref--;
	}

	// implicitly used by throw
	exception(const exception &e)
	{
		ref++;
	}
};

void
kaboom()
{
	throw	exception("kaboom");
}

int
main(int,char**)
{
	try	{
		kaboom();
	}
	
	catch(exception& e){
	}

	printf("%d\n",ref);
	
	return	0;
}

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