digitalmars.D.bugs - [Issue 2571] New: const static arrays: const(T)[N] and const(T[N]) are the same, but DMD treats them as different
- d-bugmail puremagic.com (60/60) Jan 10 2009 http://d.puremagic.com/issues/show_bug.cgi?id=2571
- d-bugmail puremagic.com (35/35) Jan 10 2009 http://d.puremagic.com/issues/show_bug.cgi?id=2571
- d-bugmail puremagic.com (9/9) Jun 24 2010 http://d.puremagic.com/issues/show_bug.cgi?id=2571
- d-bugmail puremagic.com (12/12) Jun 24 2010 http://d.puremagic.com/issues/show_bug.cgi?id=2571
- d-bugmail puremagic.com (10/10) Nov 07 2010 http://d.puremagic.com/issues/show_bug.cgi?id=2571
- d-bugmail puremagic.com (11/11) Nov 07 2010 http://d.puremagic.com/issues/show_bug.cgi?id=2571
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: bugzilla digitalmars.com ReportedBy: smjg 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 ---------- --
Jan 10 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2571 smjg iname.com changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|const static arrays: |const/invariant/immutable |const(T)[N] and const(T[N]) |static arrays: const(T)[N] |are the same, but DMD treats|and const(T[N]) are the |them as different |same, but DMD treats them as | |different 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.) --
Jan 10 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2571 Created an attachment (id=675) 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 24 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2571 Stewart Gordon <smjg iname.com> changed: What |Removed |Added ---------------------------------------------------------------------------- obsolete| | (From update of attachment 675) Sorry, attached to wrong bug report. Reposted on issue 4386. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 24 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2571 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bugzilla digitalmars.com 14:29:20 PST --- You're right, this is a bit of a mess and should be fixed. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 07 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2571 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED 20:42:55 PST --- http://www.dsource.org/projects/dmd/changeset/744 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 07 2010