[Issue 17927] [scope] `scope inout` parameter value can be escaped via return

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 20 14:04:03 UTC 2018


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

Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |schveiguy at yahoo.com
         Resolution|FIXED                       |---

--- Comment #12 from Steven Schveighoffer <schveiguy at yahoo.com> ---
(In reply to Walter Bright from comment #4)
> It turns out that:
> 
>   struct String {
>     inout(char)* mem2() inout scope @safe { return ptr; }
>     char* ptr;
>   }
> 
> not issuing an error is actually correct, because a parameter that is `ref
> inout` is inferred to be `return`, and the `this` parameter for `mem2` is
> `ref inout`.


What? ref inout should NOT be inferred as return. inout is a pattern match on
the mutability of the parameters, it does not necessarily imply that it is part
of the return type.

This can be handy when trying avoid code duplication when the const/immutable
is nested under several indirections (including ref).

Reopening, the original problem is not fixed. The error case added tests for
compiling the functions, but doesn't test that the result of the inout function
is scope (it should be).

--


More information about the Digitalmars-d-bugs mailing list