[Issue 20245] DIP1000: Should infer scope when taking address of ref
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jun 9 08:30:46 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=20245
Dennis <dkorpel at live.nl> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
CC| |dkorpel at live.nl
Resolution|WORKSFORME |---
--- Comment #2 from Dennis <dkorpel at 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
}
```
--
More information about the Digitalmars-d-bugs
mailing list