Thread overview
roll-up of old bugs: auto dtor not called on exception
Jan 24, 2006
Sean Kelly
correction: bug is 'dtor for auto object is called on incomplete object'
Jan 24, 2006
Sean Kelly
Jan 25, 2006
Thomas Kuehne
January 24, 2006
Seems the last few DMD releases have fixed most of the problems I've had in the past (including the template bugs--thanks Walter!).  A few remain however, and since I'm not sure they're all in DStress, I'm reposting them here.

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


import std.c.stdio;


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

C:\code\d\bugs>101_1
ctor
caught
continue
dtor

C:\code\d\bugs>
January 24, 2006
Sean Kelly wrote:
> Seems the last few DMD releases have fixed most of the problems I've had in the past (including the template bugs--thanks Walter!).  A few remain however, and since I'm not sure they're all in DStress, I'm reposting them here.
> 
> C:\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.
> 
> 
> import std.c.stdio;
> 
> 
> 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" );
>     }
>     printf( "continue\n" );
> }
> C:\code\d\bugs>dmd 101_1.d
> C:\bin\dmd\bin\..\..\dm\bin\link.exe 101_1,,,user32+kernel32/noi;
> 
> C:\code\d\bugs>101_1
> ctor
> caught
> continue
> dtor
> 
> C:\code\d\bugs>
January 25, 2006
Sean Kelly schrieb am 2006-01-24:
> Sean Kelly wrote:
>> Seems the last few DMD releases have fixed most of the problems I've had in the past (including the template bugs--thanks Walter!).  A few remain however, and since I'm not sure they're all in DStress, I'm reposting them here.
>> 
>> C:\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.
>> 
>> 
>> import std.c.stdio;
>> 
>> 
>> 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" );
>>     }
>>     printf( "continue\n" );
>> }
>> C:\code\d\bugs>dmd 101_1.d
>> C:\bin\dmd\bin\..\..\dm\bin\link.exe 101_1,,,user32+kernel32/noi;
>> 
>> C:\code\d\bugs>101_1
>> ctor
>> caught
>> continue
>> dtor
>> 
>> C:\code\d\bugs>

Extended
http://dstress.kuehne.cn/run/destructor_04.d
to
http://dstress.kuehne.cn/run/a/auto_14_A.d
http://dstress.kuehne.cn/run/a/auto_14_B.d

Thomas