www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12761] New: rvalue object with alias this to lvalue produces

https://issues.dlang.org/show_bug.cgi?id=12761

          Issue ID: 12761
           Summary: rvalue object with alias this to lvalue produces
                    rvalue
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: monarchdodra gmail.com

Given an object with an alias this that references an lvalue:

//----
struct S
{
    static int i;
    alias i this;
}
//----

Then, take two functions that take by auto-ref and ref:

//----
void foo(T)(auto ref T i) 
{
    pragma(msg, __traits(isRef, i)); 
}
void bar(ref int i);
//----

Finally, call them with an "RValue s". The alias this from S should create an
lvalue int:

//----
void main()
{
    foo!int(S());
    bar(S());
}
//----

However, it is not the case:
This produces:
false
Error: function main.bar (ref int i) is not callable using argument types (S)

I think this should work.

--
May 18 2014