Summary: String corruption when passing static char arrays to
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos

--- Comment #0 from Andrej Mitrovic <> 2011-06-18 
10:18:57 PDT ---
This is fairly odd behavior:

Case 1:
char[9] statCArr = "blablabla";
auto res1 = to!(char[])(statCArr);    

writeln(res1);          // writes M @
writeln(statCArr[]);    // writes blablabla

Case 2:
char[9] statCArr = "blablabla";
auto res1 = to!(char[])(statCArr);    

writeln(res1);          // writes L @
writeln(statCArr);    // writes blablabla

Note: I've only removed the square brackets and this somehow ends up changing
the garbage value of res1. You can add random writeln() statements before the
call to and res would get different results.

If you reduce the character count then you get a compile time error:

char[6] statCArr = "blabla";
auto res2 = to!(char[])(statCArr);

D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\conv.d(99): Error: template
std.conv.toImpl(T,S) if (!implicitlyConverts!(S,T) && isSomeString!(T) &&
isInputRange!(Unqual!(S)) &&
isSomeChar!(ElementType!(S))) toImpl(T,S) if (!implicitlyConverts!(S,T) &&
isSomeString!(T) && isInputRange!(Unqual!(S)) && isSomeChar!(ElementType!(S)))
matches more than one
template declaration,
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\conv.d(231):toImpl(T,S) if
(isStaticArray!(S)) and
if (implicitlyConverts!(Source,Target))

So is pretty buggy for static arrays..

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to