Bug 22653 – @safe @nogc delegate should allocate but doesn't, calls member function on dead object

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-01-07T04:09:03Z
Last change time
2024-12-13T19:20:14Z
Keywords
safe
Assigned to
No Owner
Creator
Nicholas Wilson
Moved to GitHub: dmd#20033 →

Comments

Comment #0 by iamthewilsonator — 2022-01-07T04:09:03Z
``` import std; void main() @safe @nogc { auto what = exfiltrate(); what(); } auto exfiltrate() @safe @nogc { S2 s2; s2.temp = &s2.s.foo; return (s2.bar()); } struct S2 { S s; void delegate() @safe @nogc temp; auto bar() @safe @nogc { return temp; } } struct S { int i = 42; @nogc @safe ~this() { i = 0; } void foo() @trusted @nogc { printf("ok %d", i); } } ``` This should not compile, it does and prints `ok 0`, meaning it got called on a dead object
Comment #1 by robert.schadek — 2024-12-13T19:20:14Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20033 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB