Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/wchar_t.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Added `__c_wchar_t` as a correct mangling type for C's `wchar_t`

This allows code interfacing with C++ that uses `wchar_t` to link correctly.
It replaces `wchar` (Windows) and `dchar` (Posix) as the memory type for the
DRuntime alias `wchar_t`.
10 changes: 10 additions & 0 deletions src/dmd/dcast.d
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,16 @@ MATCH implicitConvTo(Expression e, Type t)
m = MATCH.convert;
result = m;
return;
case Tenum:
if ((cast(TypeEnum)tn).sym.isSpecial())
{
/* Allow string literal -> const(wchar_t)[]
*/
if (TypeBasic tob = tn.toBasetype().isTypeBasic())
result = tn.implicitConvTo(tob);
return;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation here looks off. I can't tell whether the early return here should be part of the first or second condition.

}
break;
default:
break;
}
Expand Down
16 changes: 16 additions & 0 deletions test/compilable/implicitconv.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
enum __c_wchar_t : wchar;

alias wchar_t = __c_wchar_t;

immutable(wchar_t)[] a = "somestring";
const(wchar_t)[] b = "somestring";
immutable(wchar_t)* c = "somestring";
const(wchar_t)* d = "somestring";

string foo = "foo";

static assert(!__traits(compiles, { immutable(wchar_t)[] bar = foo; } ));
static assert(!__traits(compiles, { const(wchar_t)[] bar = foo; } ));
static assert(!__traits(compiles, { immutable(wchar_t)* bar = foo; } ));
static assert(!__traits(compiles, { const(wchar_t)* bar = foo; } ));