core.exception.InvalidMemoryOperationError@(0)
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jan 25 14:46:56 PST 2015
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
More information about the Digitalmars-d-learn
mailing list