[Issue 15832] Crashing program when a helper template function is used to create a template struct

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Mar 28 08:11:43 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=15832

--- Comment #8 from ag0aep6g at gmail.com ---
(In reply to Atila Neves from comment #7)
> In the following code, the length is garbage, and uncommenting an assert
> makes the problem move!

I think a garbage reference to the stack explains this well. Any change to the
stack between the Mock construction and a call to dg affects what dg sees when
it dereferences the garbage pointer. Adding/removing almost anything, including
asserts, is going to change what's on the stack.

You can also make the first assert in main fail. Or you can make the second one
pass when trying hard enough:

----
/* ... as above ... */

void messWithTheStack() {int[][4] x = void; x[0][0] = 42;}

void main() {
    //auto m = Mock!(typeof(dg))(dg);
    auto m = mock(dg); // this should be equivalent but crashes
    assert(dg(3) == 0);
    m.returnValue(42);
    messWithTheStack();
    assert(dg(3) == 42);
}
----

--


More information about the Digitalmars-d-bugs mailing list