[Issue 12211] Assignment expression is not an lvalue

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 20 21:33:05 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=12211



--- Comment #2 from Kenji Hara <k.hara.pg at gmail.com> 2014-02-20 21:33:01 PST ---
Note that, "an assignment expression should make an lvalue" will be consistent
with the behavior of the implicitly generated opAssign methods for user defined
structs.

import core.stdc.stdio;
struct S
{
    this(this) { printf("postblit\n"); }
}
void main()
{
    S a;
    S b;
    pragma(msg, typeof(S.opAssign));
    // Prints: pure nothrow ref @safe S(S p)
    // So, the implicitly generated opAssign returns the reference of the
    // assigned value.

    b = (a = S());
    // is translated to: b(a.opAssign(S()))
    // and the lvalue a.opAssign(S()) makes a copy.
    // Therefore, in runtime this line will print one "postblit".
}

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


More information about the Digitalmars-d-bugs mailing list