D - destructor bug [v0.58]
- Mike Wynn (57/57) Mar 06 2003 just taken me an hour to track this one down;
just taken me an hour to track this one down; (yes I know close will get called twice on strm, the real code can handle that) for some reason having a byte[] inside the templated class causes the program to crash on exit (even initialising it to null or new byte[1]; does not help ) as far as I can tell (initially I thought that the abstract close() was getting called hence its commented out) there is nothing programatically wrong with this code. import c.stdio; class InputStream { public: this() { } ~this() { printf("~this((\n"); close(); printf("))\n");} void close() { printf("OOPS\n"); } // abstract void close(); } class FileInputStream : InputStream { public: this( wchar[] name ) { } void close() { printf( "+close FileIS\n" ); } } template Filters( IStreamT : InputStream ) { class FilteredInputStream : InputStream { protected IStreamT stream; this( IStreamT strm ) { stream = strm; } void close() { printf("fis {\n"); stream.close(); printf("foo}"); } } class BufferedInputStream : FilteredInputStream { byte[] buffer; // remove this and it works this( IStreamT strm, int buflen ) { super( strm ); // buffer = null; } this( IStreamT strm ) { this( strm, 4096 ); } } } alias instance Filters(FileInputStream).BufferedInputStream buffer; int main( char[][] argv ) { try { FileInputStream strm = new FileInputStream("foo"); buffer b = new buffer( strm ); } catch (Exception e) { printf( "Exception %.*s", e.msg ); } finally { printf( "Done0.\n" ); } return 0; }
Mar 06 2003