The following code fails with a "Bus error" (OSX speak for "Segfault," if I understand correctly).

// types.d
import std.stdio;

class A {
    int x = 42;
}

void fail_sometimes(int n) {
    A a;
    if (n == 0) {
        a = new A;  // clearly a contrived example
    }
    assert(a.x == 42, "Wrong x value");
}

void main() {
    fail_sometimes(1);
}

It's even worse if I do a 'dmd -run types.d', it just fails without even the minimalistic "Bus error." Is this correct behavior? I searched the archives & looked at the FAQ & found workarounds (registering a signal handler), but not a justification, and the threads were from a couple years ago. Wondering if maybe something has changed and there's a problem with my system?

--
rwsims

Reply via email to