This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
gcc 2.95.2 fails to destroy objects created by 'throw'
- To: bug-gcc at gnu dot org
- Subject: gcc 2.95.2 fails to destroy objects created by 'throw'
- From: Chris Wedgwood <cw at f00f dot org>
- Date: Mon, 20 Mar 2000 12:56:06 +1200
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;
}