[Issue 19752] dip1000 isn't @safe if struct contains a slice

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 4 08:35:04 UTC 2020


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

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla at digitalmars.com
         Resolution|---                         |INVALID

--- Comment #4 from Walter Bright <bugzilla at digitalmars.com> ---
Let's do a little rewriting:

----
struct Range { Container *self; }

struct Container {
    int* p;

    static Range range(return scope ref Container c) @safe {
        return Range(&c);
    }
}
----

which produces the same error. More rewrites:

----
struct Range { Container *self; }

struct Container { int* p; }

Range range(return scope ref Container c) @safe {
    return Range(&c);
}
----

produces the same error. More:

----
struct Container { int* p; }

Container* range(return scope ref Container c) @safe {
    return &c;
}
----

produces the same error. More:

----
int** range(return scope ref int* c) @safe {
    return &c;
}
----

produces the same error:

Error: cannot take address of ref parameter c in @safe function range

Now, the return value is not `ref`, so the `return` applies to the `int*`, not
the `ref`. But we're not returning the `int*`, we're returning the address of
the `int*` and recall the `return` doesn't apply to that, hence the error.

--


More information about the Digitalmars-d-bugs mailing list