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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 14 12:43:00 PST 2006


http://d.puremagic.com/bugzilla/show_bug.cgi?id=51

           Summary: String cast overrides the char type of decorated string
                    literals.
           Product: D
           Version: 0.149
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: daiphoenix at lycos.com


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].


-- 




More information about the Digitalmars-d-bugs mailing list