Bug 23627 – lazy params don't allocate closures

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-01-15T01:35:36Z
Last change time
2024-12-13T19:26:38Z
Assigned to
No Owner
Creator
Adam D. Ruppe
Blocks
23628
Moved to GitHub: dmd#20212 →

Comments

Comment #0 by destructionator — 2023-01-15T01:35:36Z
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.
Comment #1 by robert.schadek — 2024-12-13T19:26:38Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20212 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB