www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - roll-up of old bugs: auto dtor not called on exception

C:\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.


import std.c.stdio;


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" );
}
C:\code\d\bugs>dmd 101_2
C:\bin\dmd\bin\..\..\dm\bin\link.exe 101_2,,,user32+kernel32/noi;

C:\code\d\bugs>101_2
main begin
ctor
caught
main end
dtor
Jan 24 2006