[Issue 9035] New: Nested struct `init` is lvalue and can be modified

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 16 04:56:30 PST 2012


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

           Summary: Nested struct `init` is lvalue and can be modified
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: verylonglogin.reg at gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2012-11-16 15:56:27 MSK ---
---
struct S { }

void f(T)(auto ref T t)
{ static assert(!__traits(isRef, t)); }

void main()
{
    f(S.init); // ok, rvalue
    f(S());    // ok, rvalue

    int i;
    struct Nested
    { int j = 0; void f() { ++i; } }
    f(Nested()); // ok, rvalue
    f(Nested.init); // fails, lvalue

    assert(Nested.init.j == 0);
    (ref n) { n.j = 5; }(Nested.init);
    assert(Nested.init.j == 0); // fails, j is 5
}
---

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