This is a follow-up to the thread »Expression::apply, DeclarationExp and a possible nested context bug« on dmd-internals: http://forum.dlang.org/thread/CAP9J_HXG8mTtnojU9YwYuSGZp1NQCdY0+7oeHyoQ2WhNR-dAuw@mail.gmail.com
The following test case shows that the problem I brought up there there also leads to wrong-code bugs in DMD (at least I hope it's still the original problem, I simply extended this from the minimal testcase linked in the thread):
---
extern(C) void printf(const char*, ...);
struct HasPostblit {
this(this) {};
}
struct Foo {
HasPostblit hp;
int i;
}
void print(Foo f) {
printf("%x\n", f.i);
}
auto toDg(E)(lazy E e) {
return { return e(); };
}
auto getDg() {
Foo a;
a.i = 0x1;
return toDg(print(a));
}
void smashStack() {
int[1024] dummy = 0xcafebabe;
}
void main() {
auto d = getDg();
smashStack();
d();
}
---
Comment #1 by clugdbug — 2012-11-05T00:50:41Z
Quite likely to be related to at least one of the other closure bugs:
bug 1841, bug 1759, bug 2148, bug 6141.
Comment #2 by code — 2012-11-11T13:59:18Z
@Don: For an analysis of why this happens and a minimal test case, see the linked dmd-internals thread (I'm fairly sure that it is correct, having spent quite some time tracking down the issue in LDC). As to whether this is related to the other bugs, I'm not sure OTOH if an intermediary DeclarationExp is also generated for them.