[Issue 23579] New: static locals cannot be initialized with stack locals

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Dec 26 04:45:00 UTC 2022


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

          Issue ID: 23579
           Summary: static locals cannot be initialized with stack locals
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: b2.temp at gmx.com

The semantics of static locals should be changed to allow ttheir initialization
with stack locals or parameters. For example, the following example does not
compile

```
void v(int a)
{
    static int b = a;
}   
```

because

> test.d:3:20: Error: variable `a` cannot be read at compile time

but that should be accepted because it is equivalent to

```
void v(int a)
{
    static int b;
    b = a;
}   
```

as `b` is only visible in `v` scope.

--


More information about the Digitalmars-d-bugs mailing list