ref for (const) variables

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 17 11:21:19 PDT 2015


On 03/17/2015 11:14 AM, Jonathan M Davis via Digitalmars-d-learn wrote:

 > Or, take this example which (unfortunately) currently compiles:
 >
 > ref int getBar(ref int bar) @safe
 > {
 >      return bar;
 > }
 >
 > ref int getFoo() @safe
 > {
 >      int foo;
 >      return getBar(foo);
 > }
 >
 > void main()
 > {
 >      getFoo() = 7;
 > }

[...]

 > I believe that the return attribute stuff that was recently added is
 > intended to solve these issues

Yes, it is available on git head (and works without @safe):

ref int getBar(return ref int bar) @safe    // <-- Add 'return'
{
      return bar;
}

ref int getFoo() @safe
{
      int foo;
      return getBar(foo);    // <-- Does not compile anymore
}

 > so I'm not very familiar with the details.

I think there are corner cases that even the 'return' attribute does not 
solve but I did not follow those discussions.

Ali



More information about the Digitalmars-d-learn mailing list