[Issue 12761] New: rvalue object with alias this to lvalue produces rvalue

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun May 18 00:17:37 PDT 2014


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 at puremagic.com
          Reporter: monarchdodra at 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.

--


More information about the Digitalmars-d-bugs mailing list