www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20108] New: -dip1000 defeated by auto

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

          Issue ID: 20108
           Summary: -dip1000 defeated by auto
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: maxhaton gmail.com

https://run.dlang.io/is/diWtCa
---------------------------------------------------------
import std;

 safe auto test(scope int* x)
{
    int y = 69;
    x = &y; //bad
    return x;
}

void main()
{
    auto y = test(null);
    writeln("Would you like some stack memory?");
    writeln(*y);

}
---------------------------------------------------------
Currently compiles, whereas replacing auto with int* will make the compiler
complain about a scope variable being returned (as it should).

If we preemptively declare test as:

auto test(return scope* x) {...} then the compiler notices the assignment of a
stack reference.

--
Aug 04 2019