[Issue 22653] New: @safe @nogc delegate should allocate but doesn't, calls member function on dead object
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jan 7 04:09:03 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22653
Issue ID: 22653
Summary: @safe @nogc delegate should allocate but doesn't,
calls member function on dead object
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: iamthewilsonator at hotmail.com
```
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
--
More information about the Digitalmars-d-bugs
mailing list