www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21212] New: [DIP1000] taking `ref` parameter address check

https://issues.dlang.org/show_bug.cgi?id=21212

          Issue ID: 21212
           Summary: [DIP1000] taking `ref` parameter address check leaking
                    when dip1000 is enabled
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Mac OS X
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: outland.karasu gmail.com

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/rii2s5$2ms5$1 digitalmars.com

----
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
----

--
Aug 30 2020