Bug 6770 – inout is allowed on fields

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-10-05T06:48:00Z
Last change time
2011-10-06T14:44:04Z
Keywords
accepts-invalid, patch
Assigned to
nobody
Creator
schveiguy

Comments

Comment #0 by schveiguy — 2011-10-05T06:48:16Z
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.
Comment #1 by schveiguy — 2011-10-05T08:06:15Z
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.
Comment #2 by k.hara.pg — 2011-10-05T17:40:23Z
Comment #3 by bugzilla — 2011-10-06T14:44:04Z