[Issue 19639] New: Initializing static array with slice enum of different length crashes the compiler

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Feb 2 20:35:47 UTC 2019


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

          Issue ID: 19639
           Summary: Initializing static array with slice enum of different
                    length crashes the compiler
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: kinke at gmx.net

```
enum EMPTY_STRING = "\0"[0..0];
void main() { char[64] buf = EMPTY_STRING; }
```

According to https://run.dlang.io/is/zQsYSf, this results in runtime errors for
v2.060-65 ('array length mismatch'), compiles successfully (!) for v2.066-70,
and crashes the compiler since 2.071.

Note that `void main() { char[64] buf = "\0"[0..0]; }` results in runtime
errors for all tested versions.

A non-empty slice `enum EMPTY_STRING = "\0"[0..1]` compiles successfully (!)
since v2.066, while previous versions and `void main() { char[64] buf =
"\0"[0..1]; }` yield runtime errors.

It's not just initializations, but assignments too (`void main() { char[64]
buf; buf = EMPTY_STRING; }`).

Originally posted here: https://github.com/ldc-developers/ldc/issues/2882

--


More information about the Digitalmars-d-bugs mailing list