Bug 21212 – [DIP1000] taking `ref` parameter address check leaking when dip1000 is enabled

Status
RESOLVED
Resolution
DUPLICATE
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-08-31T06:58:36Z
Last change time
2021-06-10T18:11:54Z
Keywords
accepts-invalid, safe
Assigned to
No Owner
Creator
Akira Yamaguchi

Comments

Comment #0 by outland.karasu — 2020-08-31T06:58:36Z
When enabled DIP1000, DMD(v2.093.1) allow taking `ref` parameter address. But it should be compile error as disabled DIP1000. reduced code by ag0aep6g https://forum.dlang.org/post/[email protected] ---- class MinPointerRecorder { int* minPrice; void update(ref int price) @safe { minPrice = &price; /* Should not compile. */ } } void main() @safe { auto r = new MinPointerRecorder; () { int mp = 42; r.update(mp); } (); () { ulong[1000] stomp = 13; } (); import std.stdio: writeln; writeln(*r.minPrice); /* Prints "13". */ } ---- rdmd result (v2.093.1 Darwin Kernel Version 19.6.0 x86_64) ---- % dmd --version DMD64 D Compiler v2.093.1 % rdmd -preview=dip1000 issue.d 13 % rdmd issue.d issue.d(6): Error: cannot take address of parameter price in @safe function update ----
Comment #1 by dlang-bot — 2021-05-20T18:04:31Z
@UplinkCoder created dlang/dmd pull request #12545 "Fix Issue 21212 - Segfault with -dip1000" fixing this issue: - Fix Issue 21212 - Segfault with -dip1000 https://github.com/dlang/dmd/pull/12545
Comment #2 by dkorpel — 2021-06-10T18:11:54Z
`update` is not `scope`, and taking the address of a `ref` should result in a scope pointer, which can't be assigned to non-scope `this`. Therefore this is the same as "Issue 20245 - DIP1000: Should infer scope when taking address of ref" *** This issue has been marked as a duplicate of issue 20245 ***