Thread overview
[Issue 20245] DIP1000: Should infer scope when taking address of ref
Sep 26, 2019
Walter Bright
Jun 09
Dennis
Jun 10
Dennis
September 26, 2019
https://issues.dlang.org/show_bug.cgi?id=20245

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |safe

--
March 15
https://issues.dlang.org/show_bug.cgi?id=20245

moonlightsentinel@disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |moonlightsentinel@disroot.o
                   |                            |rg
         Resolution|---                         |WORKSFORME

--- Comment #1 from moonlightsentinel@disroot.org ---
Works fine with current master:

----------------------------------------------
@safe int** foo(ref scope int* x)
{
  int** a = &x;
  return a;
}

@safe int* fooRet(return ref int x)
{
  int* a = &x;
  return a;
}
----------------------------------------------

./generated/linux/release/64/dmd -c -o- -dip1000 dip_escape.d
dip_escape.d(3): Error: cannot take address of `scope` parameter `x` in `@safe`
function `foo

--
June 09
https://issues.dlang.org/show_bug.cgi?id=20245

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |dkorpel@live.nl
         Resolution|WORKSFORME                  |---

--- Comment #2 from Dennis <dkorpel@live.nl> ---
(In reply to moonlightsentinel from comment #1)
> Works fine with current master:
> 
> ----------------------------------------------
> @safe int** foo(ref scope int* x)
> {
>   int** a = &x;
>   return a;
> }

That only works because `x` is a `scope` pointer, and the compiler can't give double `scope` to it when taking its address. The original example of a non-scope ref still compiles:

```
@safe:
int* foo(ref int x) {
    int* a = &x;
    return a;
}


void main() {
    int* ptr;
    {
        int x;
        ptr = foo(x);
    }
    // x escaped via ptr here
}
```

--
June 10
https://issues.dlang.org/show_bug.cgi?id=20245

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |outland.karasu@gmail.com

--- Comment #3 from Dennis <dkorpel@live.nl> ---
*** Issue 21212 has been marked as a duplicate of this issue. ***

--