[Issue 22916] [dip1000] copy of ref return still treated as scope variable

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 15 15:08:14 UTC 2022


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

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at digitalmars.com

--- Comment #1 from Walter Bright <bugzilla at digitalmars.com> ---
Here's the problem:

    ref int* index() return scope {
        return *ptr;
    }

The `scope` applies to the `this` reference, in this case, `ptr`. Although the
*ptr is not `scope`, because `scope` is not transitive, the compiler transfers
the `scope` to the return value because it is told to. (This is a feature, not
a bug.)

--


More information about the Digitalmars-d-bugs mailing list