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



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




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




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



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




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


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