Thread overview
[Issue 6032] New: wstring literals cannot be implicitly converted to const(wchar)*
May 18, 2011
Andrej Mitrovic
May 19, 2011
kennytm@gmail.com
May 19, 2011
Andrej Mitrovic
May 18, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6032

           Summary: wstring literals cannot be implicitly converted to
                    const(wchar)*
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2011-05-18 14:17:58 PDT ---
void main()
{
    const(char)*  cptr  = "foo";  // ok
    const(wchar)* wcptr = "foo"w; // error
}

Error: cannot implicitly convert expression ("foo"w) of
type immutable(wchar)[] to const(wchar)*

By fixing this it should eliminate the need to call std.utf.toUTF16z on string literals passed to WinAPI functions expecting zero-terminated wide strings.

Note that dstrings suffer from the same issue:
const(dchar)* dcptr = "foo"d;  // error

However I'm not sure if there are any C libraries which would take a UTF32 zero-terminated string. It would be consistent to make them all behave the same way though.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 19, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6032


kennytm@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm@gmail.com


--- Comment #1 from kennytm@gmail.com 2011-05-18 21:07:53 PDT ---
You could use the postfix-less version. A string literal is convertible to
immutable(<any>char)[] and immutable(<any>char)*. (That should apply to "..."w
though).

    const(wchar)* wcptr = "foo";

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 19, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6032



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2011-05-18 21:38:15 PDT ---
I forgot about that, thanks for the reminder.

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