D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20170 - [dip1000] scope and return not inferred for auto ref parameter
Summary: [dip1000] scope and return not inferred for auto ref parameter
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-26 16:30 UTC by Paul Backus
Modified: 2020-06-13 21:05 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Paul Backus 2019-08-26 16:30:17 UTC
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.
Comment 1 Paul Backus 2020-06-13 21:05:51 UTC
As of DMD v2.092.0 the given example compiles without errors.