Bug 3133 – Compiler does not check that static array casts are legal

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2009-07-03T18:48:00Z
Last change time
2014-03-01T00:36:32Z
Keywords
accepts-invalid, patch
Assigned to
nobody
Creator
jarrett.billingsley

Comments

Comment #0 by jarrett.billingsley — 2009-07-03T18:48:28Z
When doing casts on dynamic arrays, invalid casts (i.e. where the sizes of the source and destination arrays do not have a 0 remainder) are correctly diagnosed as an error: short[] x = [1]; int[] y = cast(int[])x; // error, array cast misalignment The equivalent operation performed on static arrays should be diagnosable at compile-time, but isn't: short[1] x = [1]; int[1] y = cast(int[1])x; // accepted, even though illegal writefln("%s", y[0]); // prints garbage
Comment #1 by yebblies — 2011-07-03T01:41:51Z
Comment #2 by bugzilla — 2011-10-02T20:58:14Z