[Issue 20170] New: [dip1000] scope and return not inferred for auto ref parameter

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 26 16:30:17 UTC 2019


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

          Issue ID: 20170
           Summary: [dip1000] scope and return not inferred for auto ref
                    parameter
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

struct S
{
    string value;

    @safe this()(auto ref string val)
    {
        value = val;
    }
}

@safe S create(return string arg)
{
    return S(arg);
}

---

The example above fails to compile, with the following error:

Error: returning `S(null).this(arg)` escapes a reference to parameter `arg`,
perhaps annotate with `return`

Adding `scope return` to the constructor's parameter allows the example to
compile successfully, which suggests that they are not being correctly
inferred, even though the constructor is a template.

--


More information about the Digitalmars-d-bugs mailing list