Bug 13763 – std.string.representation of immutables
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-11-22T13:09:12Z
Last change time
2018-10-13T11:12:57Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2014-11-22T13:09:12Z
I am not sure this is a bug, but it seems an incongruence:
void main() {
import std.string: representation;
enum Enum : char { A = 'a' }
const Enum[] a1;
auto r1 = a1.representation; // OK
immutable Enum[] a2;
auto r2 = a2.representation; // Error
}
dmd 2.067alpha gives:
...\dmd2\src\phobos\std\string.d(1769,12): Error: cast from immutable(Enum)[] to immutable(ubyte)[] not allowed in safe code
temp.d(7,17): Error: template instance std.string.representation!(immutable(Enum)) error instantiating
Comment #1 by dechcaudron+issues.dlang — 2018-10-13T11:12:57Z
As in DMD v2.082.1, this compiles and executes as expected. Example code:
void main() {
import std.string: representation;
import std.stdio;
enum Enum : char { A = 'a', B='b', C='c'}
const Enum[] a1 = [Enum.A, Enum.B];
writeln(a1.representation); // [97, 98]
immutable Enum[] a2 = [Enum.A, Enum.C];
writeln(a2.representation); // [97, 99]
}
I am unsure as to whether this was "accidentally" fixed as part of the regular evolution of Phobos or was reported in a duplicate issue in fixed as a response to such. Either way, that's one issue less.