http://d.puremagic.com/issues/show_bug.cgi?id=2571
Summary: const static arrays: const(T)[N] and const(T[N]) are the same, but DMD treats them as different Product: D Version: 2.023 Platform: PC OS/Version: Windows Status: NEW Keywords: rejects-valid, wrong-code Severity: normal Priority: P2 Component: DMD AssignedTo: bugzi...@digitalmars.com ReportedBy: s...@iname.com You can apply const to the whole of a static array type or to the element type thereof. Since static arrays have value semantics, the result is the same: you can neither change an element in the array nor reassign to it a whole new array. Nonetheless, DMD treats them as different types: ----- const_static_array_1.d ----- const(char)[26] abc1 = "abcdefghijklmnopqrstuvwxyz"; const(char[26]) abc2 = "abcdefghijklmnopqrstuvwxyz"; pragma(msg, typeof(abc1).stringof); pragma(msg, typeof(abc2).stringof); pragma(msg, (const(char)[26]).stringof); pragma(msg, (const(char[26])).stringof); pragma(msg, is(typeof(abc1) : typeof(abc2)).stringof); pragma(msg, is(typeof(abc2) : typeof(abc1)).stringof); pragma(msg, is(typeof(abc1) == typeof(abc2)).stringof); ---------- C:\Users\Stewart\Documents\Programming\D\d2\tests>dmd -c const_static_array_1.d const(char)[26u] const(char[26u]) const(char)[26u] const(char[26u]) true true false ---------- Moreover, while they are implicitly convertible, that they are treated as different types creates a silly template incompatibility: ----- const_static_array_2.d ----- const(char)[26] abc1 = "abcdefghijklmnopqrstuvwxyz"; const(char[26]) abc2 = "abcdefghijklmnopqrstuvwxyz"; class Temp(T) {} void main() { Temp!(const(char)[26]) t1; Temp!(const(char[26])) t2; t1 = t2; t2 = t1; } ---------- C:\Users\Stewart\Documents\Programming\D\d2\tests>dmd const_static_array_2.d const_static_array_2.d(10): Error: cannot implicitly convert expression (t2) of type const_static_array_2.Temp!(const(char[26u])).Temp to const_static_array_2.Temp!(const(char)[26u]).Temp const_static_array_2.d(11): Error: cannot implicitly convert expression (t1) of type const_static_array_2.Temp!(const(char)[26u]).Temp to const_static_array_2.Temp!(const(char[26u])).Temp ---------- --