www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22519] New: [dip1000] cannot take address of `ref return`


          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 puremagic.com
          Reporter: dkorpel live.nl

Compile with -preview=dip1000
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. --
Nov 18 2021