[Issue 5909] New: Allow implicit conversion of string literal (in particular x"") to immutable(ubyte)[]

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Apr 29 09:14:47 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5909

           Summary: Allow implicit conversion of string literal (in
                    particular x"") to immutable(ubyte)[]
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P4
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: kennytm at gmail.com


--- Comment #0 from kennytm at gmail.com 2011-04-29 09:10:59 PDT ---
As titled.

Some string features like \x escape characters and x"" string may produce an
invalid UTF string. This may not be useful for the 'string' type, but is very
useful for creating a 'ubyte[]' type which isn't limited by the character set.

Unfortunately, correctly a string literal can only be implicitly converted to
an immutable char/wchar/dchar pointer/array, so the following will not work
without a cast:

-------------------------------
void main() {
    immutable(ubyte)[] a = x"1a b2 3c d4 5e f6";
}
-------------------------------
$ dmd x
x.d(2): Error: cannot implicitly convert expression ("\x1a\xb2<\xd4^\xf6") of
type string to immutable(ubyte)[]
-------------------------------

(See also issue 2193 for a generalization.)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list