[Issue 24754] cannot take address of a member array in a ref foreach

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 13 02:21:29 UTC 2024


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

--- Comment #9 from Luís Ferreira <contact at lsferreira.net> ---
(In reply to Dennis from comment #8)
> Reduces to:
> 
> ```D
> void main() @safe
> {
>     foreach(ref e; new int[1])
>         int* f = &e;
> }
> ```

Thanks! So, maybe this should also be valid, but more arguable if requires
dip1000 internal checks the same way with `ref`, although, spec-wise it should:

```
void main() @safe
{
    foreach(e; new int[1])
        int* f = &e;
}
```

I removed the `ref`, `f` doesn't escape its own scope, the same way this should
compile:

```
void main() @safe
{
    int e;
    int* f = &e;
}
```

--


More information about the Digitalmars-d-bugs mailing list