digitalmars.D.bugs - [Issue 19651] New: Missing compile errors when initializing static
- d-bugmail puremagic.com (40/40) Feb 05 2019 https://issues.dlang.org/show_bug.cgi?id=19651
https://issues.dlang.org/show_bug.cgi?id=19651 Issue ID: 19651 Summary: Missing compile errors when initializing static char array with slice of mismatching length Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: kinke gmx.net When initializing with or assigning to a string slice of mismatching length, a compile error should be emitted, consistent with all other non-char/wchar/dchar types. LDC doesn't expect such cruelty in the codegen AST, at least not for static array initialization, and currently doesn't produce a runtime error, but happily reads beyond the source string. void main() { { enum src = [1, 2]; int[64] buf = src[0..64]; // runtime error: range violation buf = src[0..3]; // compile error: mismatched array lengths buf = src[0..2]; // compile error: mismatched array lengths buf = src[0..1]; // compile error: mismatched array lengths buf = src[0..0]; // compile error: cannot cast int[0] to int[64] } { enum src = "ab"; char[64] buf = src[0..64]; // runtime error: range violation buf = src[0..3]; // compile error: mismatched array lengths buf = src[0..2]; // runtime error: range violation buf = src[0..1]; // runtime error: range violation buf = src[0..0]; // runtime error: range violation } } --
Feb 05 2019