Thread overview
[Issue 20245] DIP1000: Should infer scope when taking address of ref
Sep 26, 2019
Walter Bright
Jun 09, 2021
Dennis
Jun 10, 2021
Dennis
Jul 05, 2021
Dlang Bot
Aug 22, 2021
Dlang Bot
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, 2021
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, 2021
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, 2021
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. ***

--
July 05, 2021
https://issues.dlang.org/show_bug.cgi?id=20245

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
@dkorpel created dlang/dmd pull request #12812 "Fix issue 20245 - address of ref should be scope" fixing this issue:

- fix issue 20245 - address of ref should be scope

https://github.com/dlang/dmd/pull/12812

--
August 22, 2021
https://issues.dlang.org/show_bug.cgi?id=20245

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #12812 "Fix issue 20245 - address of ref should be scope" was merged into master:

- 47fa750bc76a5835fe8c547fed30133ed2a12a8a by dkorpel:
  fix issue 20245 - address of ref should be scope

https://github.com/dlang/dmd/pull/12812

--