www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - A handful of bugs with exceptions - bugs.zip

So I decided to drop my fire-and-forget mode of bug reporting and organize a
bit.  As such, all of the bugs I report will be tagged by version number and
I'll keep on testing then with each release until they're fixed.  Hopefully
fewer issues will slip through the cracks this way.  Now, on to the bugs...

This report will contain the code for 4-5 related issues--it's likely that
fixing one of these will actually fix a few of them.  I'll paste everything in
standard format, separated by a line.  For convenience, sample code is also
attached in a zipfile.

----------------------------------------------------------------------

D:\code\d\bugs>type 101_1.d
// This demonstrates incorrect behavior for auto class
// construction.  If an exception is thrown out of a
// class ctor then it is an incomplete object and its
// dtor should not be called.

auto class AutoClass
{
public:
this()
{
printf( "ctor\n" );
throw new Exception( "" );
}

~this()
{
printf( "dtor\n" );
}
}


void main()
{
try
{
auto AutoClass c = new AutoClass();
}
catch( Exception e )
{
printf( "caught\n" );
}
}
D:\code\d\bugs>dmd 101_1.d
D:\bin\dmd\bin\..\..\dm\bin\link.exe 101_1,,,user32+kernel32/noi;

D:\code\d\bugs>101_1
ctor
caught
dtor

----------------------------------------------------------------------

D:\code\d\bugs>type 101_2.d
// This demonstrates a delayed dtor call for auto classes
// when an exception is thrown. the dtor should be called
// when execution leaves func(), not after main exits.

auto class AutoClass
{
public:
this()
{
printf( "ctor\n" );
throw new Exception( "" );
}

~this()
{
printf( "dtor\n" );
}
}


void func()
{
auto AutoClass c = new AutoClass();
}


void wrap()
{
try
{
func();
}
catch( Exception e )
{
printf( "caught\n" );
}
}


void main()
{
printf( "main begin\n" );
wrap();
printf( "main end\n" );
}
D:\code\d\bugs>dmd 101_2.d
D:\bin\dmd\bin\..\..\dm\bin\link.exe 101_2,,,user32+kernel32/noi;

D:\code\d\bugs>101_2
main begin
ctor
caught
main end
dtor

----------------------------------------------------------------------

D:\code\d\bugs>type 101_3.d
// This demonstrates a double dtor call for auto classes
// when an exception is thrown in the class dtor.  The
// dtor should only be called once (when func() exits).


auto class AutoClass
{
public:
this()
{
printf( "ctor\n" );
}

~this()
{
printf( "dtor\n" );
throw new Exception( "" );
}
}


void func()
{
auto AutoClass c = new AutoClass();
}


void main()
{
try
{
func();
}
catch( Exception e )
{
printf( "caught\n" );
}
}
D:\code\d\bugs>dmd 101_3.d
D:\bin\dmd\bin\..\..\dm\bin\link.exe 101_3,,,user32+kernel32/noi;

D:\code\d\bugs>101_3
ctor
dtor
caught
dtor
*crash*

----------------------------------------------------------------------

D:\code\d\bugs>type 101_4.d
// This will only be testable once 101_1 through 101_3 have
// been fixed.   Correct behavior should be that the class
// dtor will be called when func() exits (because an
// exception has been thrown), and this dtor's throwing of
// an exception should call terminate().  The other option
// would be to attempt some support for multiple exception
// processing.


auto class AutoClass
{
public:
this()
{
printf( "ctor\n" );
}

~this()
{
printf( "dtor\n" );
throw new Exception( "" );
}
}


void func()
{
auto AutoClass c = new AutoClass();
throw new Exception( "" );
}


void main()
{
try
{
func();
}
catch( Exception e )
{
printf( "caught\n" );
}
}
D:\code\d\bugs>dmd 101_4.d
D:\bin\dmd\bin\..\..\dm\bin\link.exe 101_4,,,user32+kernel32/noi;

D:\code\d\bugs>101_4
ctor
dtor
caught
dtor
*crash*

----------------------------------------------------------------------


begin 0644 bugs.zip

M]TB\ [O!`EVZ]-2A[2OP`B'G*Y%"#L7A;CCQ[G4P M!*YR'*WU_YV6D::'M+
M<,;AZBD&'9%`>\`0K 'N-O: C4$BH!&-O5 ,!!-9_U.HI &/%/$,QFDBI+I0
MA8HXC([;0)LN95L5ZE$H8%NRQ/TIGC4P!GOCBG=1UD>X:7<2-:>>?ZJ_CM53




M-QC&,1(!"\9QHLC]]O)H;/>AEH5G,'-GSH6ZAD.G`R \.1O("\(`(FZ-N*("


MA\9H^< 9Q$714K4M^:V$M'JO+;45;&3$>K,;V.Z7PXP-%D=XO;N)E4O-5$+Y
MOO\W07V;$-53XN?L[+3Z])G!TVEV-?L!"4\99/Y3I39K_>A%O]*3O_Y`*2.^
MPDM!LJL6 X#PURV)X=A1<;%8GTJZIDEOM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