[Issue 9069] New: struct literals are treated as lvalues

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Nov 24 02:18:19 PST 2012


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

           Summary: struct literals are treated as lvalues
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: jmdavisProg at gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg at gmx.com> 2012-11-24 02:17:54 PST ---
I thought that we'd finally fixed this, but I guess that it was changed back
for some reason. With this code,

struct S
{
    int i;
}

S foo(ref S s)
{
    return s;
}

S bar(int i)
{
    return S(i);
}

void main()
{
    S s = S(2);
    foo(s);  //compiles as it should
    foo(S(5)); //compiles when it shouldn't
    foo(bar(5)); //fails to compile as it should
}

only the final call to foo gives an error, when only the first call should
compile. The second call is succeeding when it should be failing.

It makes _no_ sense to treat struct literals as lvalues. They're _not_
variables. Why on earth would struct literals be treated any differently from
string literals or numeric literals in this regard? When it's come up in the
newsgroups, I believe that the only person who has thought that this made any
sense at all is Walter. And I thought that we'd finally gotten him to change it
so that struct literals act like every other literal and are rvalues, but given
that foo(S(5)) compiles, clearly that's not the case. It should be fixed.

-- 
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