www.digitalmars.com         C & C++   DMDScript  

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

reply Sean Kelly <sean f4.ca> writes:
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>
Jan 24 2006
parent reply Sean Kelly <sean f4.ca> writes:
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>

Jan 24 2006
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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 -----BEGIN PGP SIGNATURE----- iD8DBQFD10jj3w+/yD4P9tIRAi9iAKCyqN9MRXzE9ocUXImwx3OKqy/hhQCfZgY/ IJhsGO2oXukMDVY8rfzJ9Xs= =L91B -----END PGP SIGNATURE-----
Jan 25 2006