[Issue 23627] New: lazy params don't allocateclosures
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jan 15 01:35:36 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=23627
Issue ID: 23627
Summary: lazy params don't allocateclosures
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: destructionator at gmail.com
This assert should NOT pass:
```
struct W {
string delegate() magic;
void content(lazy string s) {
magic = &s;
}
string test;
}
void main() {
int onStack;
W w;
w.content = w.test;
auto diff = w.magic.ptr - cast(void*) &onStack;
if(diff < 0) diff = -diff;
assert(diff > 64);
}
```
Notice that if you change it to an explicit delegate:
void content(string delegate() s) {
// snip
w.content = () => w.test;
It will fail.
Can also confirm by using the disassembly to see the lack of _d_allocmemory for
the closure.
The spec explicitly permits taking the address of a lazy param to get the
delegate and it is not marked with any lifetime restrictions, so the
implementation is wrong to give it limited lifetime.
--
More information about the Digitalmars-d-bugs
mailing list