Skip to content

Commit

Permalink
Fix Issue 18958 - extern(C++) wchar, dchar mangling not correct
Browse files Browse the repository at this point in the history
  • Loading branch information
TurkeyMan committed Jun 8, 2018
1 parent da13edb commit 22fa049
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/dmd/cppmangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,8 @@ public:
case Tfloat80: c = 'e'; break;
case Tbool: c = 'b'; break;
case Tchar: c = 'c'; break;
case Twchar: c = 't'; break; // unsigned short (perhaps use 'Ds' ?
case Tdchar: c = 'w'; break; // wchar_t (UTF-32) (perhaps use 'Di' ?
case Twchar: p = 'D'; c = 's'; break; // since C++11
case Tdchar: p = 'D'; c = 'i'; break; // since C++11
case Timaginary32: p = 'G'; c = 'f'; break; // 'G' means imaginary
case Timaginary64: p = 'G'; c = 'd'; break;
case Timaginary80: p = 'G'; c = 'e'; break;
Expand Down
21 changes: 10 additions & 11 deletions src/dmd/cppmanglewin.d
Original file line number Diff line number Diff line change
Expand Up @@ -202,27 +202,26 @@ public:
case Tfloat64:
buf.writeByte('N');
break;
case Tbool:
buf.writestring("_N");
break;
case Tchar:
buf.writeByte('D');
break;
case Tdchar:
buf.writeByte('I');
break;
// unsigned int
case Tfloat80:
if (flags & IS_DMC)
buf.writestring("_Z"); // DigitalMars long double
else
buf.writestring("_T"); // Intel long double
break;
case Tbool:
buf.writestring("_N");
break;
case Tchar:
buf.writeByte('D');
break;
case Twchar:
if (flags & IS_DMC)
buf.writestring("_Y"); // DigitalMars wchar_t
else
buf.writestring("_W"); // Visual C++ wchar_t
buf.writestring("_S"); // Visual C++ char16_t (since C++11)
break;
case Tdchar:
buf.writestring("_U"); // Visual C++ char32_t (since C++11)
break;
default:
visit(cast(Type)type);
Expand Down
18 changes: 18 additions & 0 deletions test/compilable/cppmangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -731,3 +731,21 @@ extern(C++, Namespace18922)
else version(Windows)
static assert(func18922.mangleof == "?func18922@Namespace18922@@YAXUStruct18922@1@@Z");
}

/**************************************/
// https://issues.dlang.org/show_bug.cgi?id=18958
// Issue 18958 - extern(C++) wchar, dchar mangling not correct

// TODO: update with wchar_t when mangling is supported...
//extern (C++) void test_char_mangling(char, wchar, dchar, wchar_t);
extern (C++) void test_char_mangling(char, wchar, dchar);
version (Posix)
{
static assert(test_char_mangling.mangleof == "_Z18test_char_manglingcDsDi");
// static assert(test_char_mangling.mangleof == "_Z18test_char_manglingcDsDiw");
}
version (Windows)
{
static assert(test_char_mangling.mangleof == "?test_char_mangling@@YAXD_S_U@Z");
// static assert(test_char_mangling.mangleof == "?test_char_mangling@@YAXD_S_U_W@Z");
}

0 comments on commit 22fa049

Please sign in to comment.