c++ 2.95.2: goto+dtor bug
grahams
grahams@rcp.co.uk
Sat Feb 12 11:29:00 GMT 2000
Hi
This bug also exists in the current CVS as of 12th Feb.
Here are a couple of modified versions of
the original test case which show that its
only some destructors which don't get called.
Graham
---------------------------------------------------
#include <stdio.h>
class a
{
private:
int n;
public:
a(int x) { n = x; printf("ctor %d\n", n); }
~a() { printf("dtor %d\n", n); }
};
int main(int argc,char **argv)
{
a var0(0);
if(argc>1)
{
leave:
return 0;
}
a var1(1);
a var2(2);
goto leave;
}
---------------------------------------------------
Here's the output
ctor 0
ctor 1
ctor 2
dtor 2
dtor 0
---------------------------------------------------
#include <stdio.h>
class a
{
private:
int n;
public:
a(int x) { n = x; printf("ctor %d\n", n); }
~a() { printf("dtor %d\n", n); }
};
int main(int argc,char **)
{
a var0(0);
if(argc>1)
{
leave:
return 0;
}
a var1(1);
a var2(2);
if (argc>1)
{
leave2:
goto leave;
}
a var3(3);
a var4(4);
goto leave2;
}
---------------------------------------------------
Here's the output
ctor 0
ctor 1
ctor 2
ctor 3
ctor 4
dtor 4
dtor 2
dtor 0
More information about the Gcc-bugs
mailing list