← Back to index
|
Original Bugzilla link
Bug 19651 – Missing compile errors when initializing static char array with slice of mismatching length
Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-02-05T20:18:00Z
Last change time
2024-12-13T19:02:18Z
Assigned to
No Owner
Creator
kinke
Moved to GitHub: dmd#17896 →
Comments
Comment #0
by kinke — 2019-02-05T20:18:00Z
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 } }
Comment #1
by robert.schadek — 2024-12-13T19:02:18Z
THIS ISSUE HAS BEEN MOVED TO GITHUB
https://github.com/dlang/dmd/issues/17896
DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB