[Issue 22519] New: [dip1000] cannot take address of `ref return`
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Nov 18 10:00:45 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22519
Issue ID: 22519
Summary: [dip1000] cannot take address of `ref return`
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dkorpel at live.nl
Compile with -preview=dip1000
```
@safe:
void main()
{
int x;
int* a = &identity(x); // error
int* b = identity(x).addressOf; // workaround
}
ref int identity(return ref int x) {return x;}
int* addressOf(return ref int x) {return &x;}
```
> onlineapp.d(5): Error: cannot take address of `ref return` of `identity()`
> in `@safe` function `main`
This is a needless limitation. As shown, it can be worked around using the
`addressOf` function instead of the & operator.
--
More information about the Digitalmars-d-bugs
mailing list