Skip to content

Can't declare global ref variable #5536

Open
@dlangBugzillaToGithub

Description

@dlangBugzillaToGithub

Nick Treleaven reported this on 2024-08-28T15:56:27Z

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

Description

The 2.111 pending changelog says:

> ref and auto ref can now be applied to local, static, extern, and global variables

https://dlang.org/changelog/pending.html#dmd.reflocal

But globals don't seem to work:

struct Foo
{
    int a;
}

Foo foo;
ref f = foo; // Error: static variable `foo` cannot be read at compile time
ref a = foo.a; // Error: static variable `foo` cannot be read at compile time

`f` could be just an alias so to be useful, `a` needs to be supported. Assuming ref globals are supposed to work.

The only ref variable tests I found are in test/runnable/declaration.d, and none are global variables.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions