core.exception.InvalidMemoryOperationError@(0)

Bayan Rafeh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 25 15:15:48 PST 2015


On Sunday, 25 January 2015 at 22:46:56 UTC, Ali Çehreli wrote:
> On 01/25/2015 02:06 PM, Bayan Rafeh wrote:
>
>> is invariant() called during the destruction phase?
>
> Something is fishy.
>
> import std.stdio;
>
> void main(){
>     writeln("entered main");
>     auto a = new A();
>     writeln("leaving main");
> }
>
> class A {
>     File file;
>
>     this() {
>         writeln("this");
>     }
>
>     ~this() {
>         writeln("~this");
>     }
>
>     invariant() {
>         writeln("invariant");
>     }
> }
>
> The program produces the following output:
>
> entered main
> this
> invariant
> leaving main
> invariant
> invariant    <-- ?
> ~this
> invariant    <-- ?
>
> Removing the File member changes the output. Now two of the 
> invariant calls are missing:
>
> entered main
> this
> invariant
> leaving main
> invariant
> ~this
>
> However, the last invariant is still there and I think by 
> design: The destructor should see a valid state.
>
> Ali

Could this be a bug in D?


More information about the Digitalmars-d-learn mailing list