diff --git a/changelog/wchar_t.dd b/changelog/wchar_t.dd new file mode 100644 index 000000000000..1213a61f3177 --- /dev/null +++ b/changelog/wchar_t.dd @@ -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`. diff --git a/src/dmd/dcast.d b/src/dmd/dcast.d index fe85ee1ef80e..1c4e481a29dd 100644 --- a/src/dmd/dcast.d +++ b/src/dmd/dcast.d @@ -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; + } + break; default: break; } diff --git a/test/compilable/implicitconv.d b/test/compilable/implicitconv.d new file mode 100644 index 000000000000..6576a974a26e --- /dev/null +++ b/test/compilable/implicitconv.d @@ -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; } )); +