Skip to content

cannot take address of a member array in a ref foreach #18267

@dlangBugzillaToGithub

Description

@dlangBugzillaToGithub

Luís Ferreira reported this on 2024-09-09T01:45:00Z

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

CC List

  • Richard (Rikki) Andrew Cattermole
  • Dennis
  • Dominikus Dittes Scherkl
  • Nick Treleaven (@ntrel)

Description

The following code should compile:

```
struct Foo 
{
    int[] foo;
    
    @safe
    void foobar()
    {
        int* f;
        foreach(ref e; foo)
            f = &e;
    }
}

void main()
{
    Foo foo;
    foo.foobar();
}
```

Shouldn't yield:

```
Up to      2.078.3: Failure with output: onlineapp.d(10): Error: cannot take address of local e in @safe function foobar
Since      2.079.1: Failure with output: onlineapp.d(10): Error: cannot take address of local `e` in `@safe` function `foobar`
```

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions