Thread overview
[Issue 6770] New: inout is allowed on fields
Oct 06, 2011
Kenji Hara
Oct 06, 2011
Walter Bright
October 05, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6770

           Summary: inout is allowed on fields
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: schveiguy@yahoo.com


--- Comment #0 from Steven Schveighoffer <schveiguy@yahoo.com> 2011-10-05 06:48:16 PDT ---
inout cannot be allowed to be an attribute for fields, since inout is implicitly cast at the end of an inout function.

With this allowance, I can obtain a mutable pointer to an inout field, even though it should be treated as const:

struct S
{
    inout(int) x;

    inout(int)* foo() inout
    {
        return &x;
    }
}

void main()
{
    S s;
    auto xp = s.foo();
    *xp = 3;
    assert(s.x == 3);
}

inout should be a temporary condition, only allowed for stack-stored types. But fields can be placed outside the stack, since you can place any struct or class outside the stack.

Alternatively, you could be able to declare a struct field as inout, and then not allow that struct type to ever be placed anywhere but the stack.  But I do not see a good use case for that feature.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 05, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6770



--- Comment #1 from Steven Schveighoffer <schveiguy@yahoo.com> 2011-10-05 08:06:15 PDT ---
I should add that this bug is valid only for the (currently unreleased) 2.056 version, 2.055 does not have a valid inout implementation.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6770


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid, patch


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2011-10-05 17:40:23 PDT ---
https://github.com/D-Programming-Language/dmd/pull/433

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 06, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6770


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2011-10-06 14:44:04 PDT ---
https://github.com/D-Programming-Language/dmd/commit/39966f4f06a527ed67e6f1d6e948c9568a8745d0

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