[Issue 23073] New: [dip1000] scope inference from pure doesn't consider self-assignment
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Apr 30 21:50:20 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23073
Issue ID: 23073
Summary: [dip1000] scope inference from pure doesn't consider
self-assignment
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dkorpel at live.nl
```
@safe:
class C
{
C next;
}
void assignNext(C c) pure nothrow @nogc
{
c.next = c;
}
C escape() @nogc
{
scope C c = new C();
assignNext(c);
return c.next;
}
void main()
{
C dangling = escape();
}
```
`assignNext` should not be callable on a `scope` parameter. The compiler sees
no other parameters that c could be assigned to, but doesn't consider that
mutable aggregates may have extra pointer layers, allowing you to escape a
scope pointer because of the lack of transitive scope.
--
More information about the Digitalmars-d-bugs
mailing list