Bug 17341 – Partial initialization of static array should not be allowed
Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-04-22T17:22:00Z
Last change time
2017-05-06T03:43:04Z
Assigned to
nobody
Creator
b2.temp
Comments
Comment #0 by b2.temp — 2017-04-22T17:22:03Z
In this example:
```
enum E{e0,e1,e2}
static immutable int[E.max + 1] a = [0,1]; // oops no 3rd element
static assert(isStaticArray!(typeof(a))); // no detected
```
we use an enum to define the size of a static array. The ArrayInitializer only sets the 2 first elements and nothing allows to statically check the omission (that could happen for example when adding new members to an enum).
Two possible actions:
- The compiler could emit a warning for this case.
- Deprecate "partial initialization of static arrays" and update the specifications.
Comment #1 by b2.temp — 2017-04-22T17:23:11Z
(In reply to b2.temp from comment #0)
> In this example:
>
> ```
> enum E{e0,e1,e2}
> static immutable int[E.max + 1] a = [0,1]; // oops no 3rd element
> static assert(isStaticArray!(typeof(a))); // no detected
> ```
The static assert should be
static assert(a.length == E.max + 1); // not detected
Comment #2 by b2.temp — 2017-05-06T03:43:04Z
feature that can be an issue. feel free to change "wontfix" to "invalid".