Skip to content

wstring literals cannot be implicitly converted to const(wchar)* #18342

@dlangBugzillaToGithub

Description

@dlangBugzillaToGithub

Andrej Mitrovic (@AndrejMitrovic) reported this on 2011-05-18T14:17:58Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=6032

CC List

  • Nick Treleaven (@ntrel)
  • Steven Schveighoffer (@schveiguy)
  • Elie Morisse
  • yebblies

Description

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions