Skip to content

Commit 40fac70

Browse files
committed
Fix Issue 18958 - extern(C++) wchar, dchar mangling not correct
1 parent da13edb commit 40fac70

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/dmd/cppmangle.d

+2-2
Original file line numberDiff line numberDiff line change
@@ -1047,8 +1047,8 @@ public:
10471047
case Tfloat80: c = 'e'; break;
10481048
case Tbool: c = 'b'; break;
10491049
case Tchar: c = 'c'; break;
1050-
case Twchar: c = 't'; break; // unsigned short (perhaps use 'Ds' ?
1051-
case Tdchar: c = 'w'; break; // wchar_t (UTF-32) (perhaps use 'Di' ?
1050+
case Twchar: p = 'D'; c = 's'; break; // since C++11
1051+
case Tdchar: p = 'D'; c = 'i'; break; // since C++11
10521052
case Timaginary32: p = 'G'; c = 'f'; break; // 'G' means imaginary
10531053
case Timaginary64: p = 'G'; c = 'd'; break;
10541054
case Timaginary80: p = 'G'; c = 'e'; break;

src/dmd/cppmanglewin.d

+4-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ public:
222222
if (flags & IS_DMC)
223223
buf.writestring("_Y"); // DigitalMars wchar_t
224224
else
225-
buf.writestring("_W"); // Visual C++ wchar_t
225+
buf.writestring("_S"); // Visual C++ char16_t (since C++11)
226+
break;
227+
case Tdchar:
228+
buf.writestring("_U"); // Visual C++ char32_t (since C++11)
226229
break;
227230
default:
228231
visit(cast(Type)type);

test/compilable/cppmangle.d

+18
Original file line numberDiff line numberDiff line change
@@ -731,3 +731,21 @@ extern(C++, Namespace18922)
731731
else version(Windows)
732732
static assert(func18922.mangleof == "?func18922@Namespace18922@@YAXUStruct18922@1@@Z");
733733
}
734+
735+
/**************************************/
736+
// https://issues.dlang.org/show_bug.cgi?id=18958
737+
// Issue 18958 - extern(C++) wchar, dchar mangling not correct
738+
739+
// TODO: update with wchar_t when mangling is supported...
740+
//extern (C++) void test_char_mangling(char, wchar, dchar, wchar_t);
741+
extern (C++) void test_char_mangling(char, wchar, dchar);
742+
version (Posix)
743+
{
744+
static assert(test_char_mangling.mangleof == "_Z18test_char_manglingcDsDi");
745+
// static assert(test_char_mangling.mangleof == "_Z18test_char_manglingcDsDiw");
746+
}
747+
version (Windows)
748+
{
749+
static assert(test_char_mangling.mangleof == "?test_char_mangling@@YAXD_S_U@Z");
750+
// static assert(test_char_mangling.mangleof == "?test_char_mangling@@YAXD_S_U_W@Z");
751+
}

0 commit comments

Comments
 (0)