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 ----------
The type should be reported as const(char[26]) in either case. And here's another case of the same basic bug: ---------- invariant(const(char)[26]) abc1 = "abcdefghijklmnopqrstuvwxyz"; const(invariant(char)[26]) abc2 = "abcdefghijklmnopqrstuvwxyz"; pragma(msg, typeof(abc1).stringof); pragma(msg, typeof(abc2).stringof); pragma(msg, (invariant(const(char)[26])).stringof); pragma(msg, (const(invariant(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_3.d immutable(char[26u]) const(immutable(char)[26u]) immutable(char[26u]) const(immutable(char)[26u]) true true false ---------- Again, the two should denote the exact same type, invariant(char[26u]). (immutable? invariant? See also issue 2572.)
Created attachment 675 [details] Example of a squashed summary line Rendered by Firefox 3.6.3 at inner width 1000. If you make it much narrower, you get a horizontal scrollbar.
Comment on attachment 675 [details] Example of a squashed summary line Sorry, attached to wrong bug report. Reposted on issue 4386.
You're right, this is a bit of a mess and should be fixed.
http://www.dsource.org/projects/dmd/changeset/744