www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12211] New: Assignment expression is not an lvalue

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12211

           Summary: Assignment expression is not an lvalue
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: k.hara.pg gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg gmail.com> 2014-02-19 23:07:58 PST ---
Test case:

void main()
{
    int a;

    void foo(ref int x) { assert(&x == &a); }

    foo(a += 1);  // OK
    //foo(a = 1);   // doesn't compile
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 19 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12211



--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2014-02-20 21:07:40 PST ---
In C++:

#include <stdio.h>
void foo(int& x)
{
    printf("foo: x = %d\n", x);
    x = 3;
}
int main()
{
    int a = 0;
    printf("a = %d\n", a);
    foo(a += 1);
    printf("a = %d\n", a);
    foo(a = 2);
    printf("a = %d\n", a);
}

Prints:
---
a = 0
foo: x = 1
a = 3
foo: x = 2
a = 3

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 20 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12211



--- Comment #2 from Kenji Hara <k.hara.pg 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: -------
Feb 20 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12211


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2014-02-20 21:35:32 PST ---
https://github.com/D-Programming-Language/dmd/pull/3306

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 20 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12211



--- Comment #4 from github-bugzilla puremagic.com 2014-02-22 14:28:06 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/34ce06a844fdb7e365469976ae010ee179c19e62
fix Issue 12211 - Assignment expression is not an lvalue

https://github.com/D-Programming-Language/dmd/commit/7373fc1e4be70eb4003b3822cd1c39dcc7bb8223
Merge pull request #3306 from 9rnsr/fix12211

Issue 12211 - Assignment expression is not an lvalue

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 22 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12211


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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