[Bug 51] New: String cast overrides the char type of decorated string literals.

Thomas Kuehne thomas-dloop at kuehne.cn
Wed Jul 12 04:03:15 PDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

d-bugmail at puremagic.com schrieb am 2006-03-14:
> http://d.puremagic.com/bugzilla/show_bug.cgi?id=51

> Observe the following code:
>
>   char[6] cstr = "123456"c;
>   auto str1 = cast(wchar[3])(cstr);
>   auto str2 = cast(wchar[3])("123456"c);
>
>   writefln("str1: ", (cast(char[])str1).length , " : ", (cast(char[])str1));
>   // prints: str1: 6 : 123456
>   writefln("str2: ", (cast(char[])str2).length , " : ", (cast(char[])str2)); 
>   // prints: str2: 6 : ?1?2?3
>
> One would expect the same behaviour from str1 and str2, however the
> cast(wchar[3]) in str2 overrides the string decorator 'c', and makes the string
> literal "123456" (i.e. the string "instance" data) be of type wchar[6] instead
> of char[6].

Added to DStress as
http://dstress.kuehne.cn/run/s/string_postfix_07_A.d
http://dstress.kuehne.cn/run/s/string_postfix_07_B.d

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFEtOHcLK5blCcjpWoRAgakAKCOhY7VG1AkTF8IFOz1Ur067Dk+dQCeIlbj
h9EvDdFmTjEL3U2/pdpgnqk=
=rrCR
-----END PGP SIGNATURE-----



More information about the Digitalmars-d-bugs mailing list