[Issue 2521] Not possible to return immutable value by ref

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 7 04:27:26 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=2521


yebblies <yebblies at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch, rejects-valid
                 CC|                            |yebblies at gmail.com


--- Comment #5 from yebblies <yebblies at gmail.com> 2011-06-07 04:22:52 PDT ---
This bug addresses two issues.

This does not currently work:

-------------------------------

immutable int val = 23;

ref immutable(int) func()
{
    return val;
}


Error: constant 23 is not an lvalue
-------------------------------

And this gives the same terrible error message:

-------------------------------

immutable int val = 23;

ref int func()
{
    return val;
}

Error: constant 23 is not an lvalue
-------------------------------

The proposed fix (dmd pull 92) allows the first case, and changes the error to
the following for the second case:

Error: cast(int)val is not an lvalue

The root cause of this bug is the fact that while running semantic on the
return expression, the immutable variable's value is known at compile time, and
is optimized without checking if the function returns an lvalue.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list