[Issue 15651] filter: only parameters or stack based variables can be inout

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Aug 28 14:08:18 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=15651

--- Comment #7 from Steven Schveighoffer <schveiguy at yahoo.com> ---
(In reply to Harry Vennik from comment #6)
>     /* inout resolves to mutable in call to getRef */
>     c.getRef(5) = 8;  // Undefined behavior

That would fail because c.getRef(5) would return ref const(int). In order to
allow inout modifiers on structs or classes, you need to consider the type
modifier of those members in the inout placeholder calculation. In this case,
you have mutable C and inout C._arr, which result in const.

In other words, the rules aren't written yet, but they can be constructed in a
valid way. What we would be trying to accomplish is allowing encapsulation of
functionality in a struct or class, even with inout data. Most likely you don't
write getRef as an inout function.

--


More information about the Digitalmars-d-bugs mailing list