From e2a2ae12d75e4d6afbf3babafd9fde6438997243 Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Sun, 2 Dec 2018 02:26:50 -0800 Subject: [PATCH] add -version=cpp98 to compiler --- changelog/cpp98.dd | 56 ++++++++++++++++++++++++++++++++++++++++++++++ src/dmd/cond.d | 1 + src/dmd/globals.d | 1 + src/dmd/globals.h | 3 ++- src/dmd/mars.d | 16 ++++++++++--- 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 changelog/cpp98.dd diff --git a/changelog/cpp98.dd b/changelog/cpp98.dd new file mode 100644 index 000000000000..c63f90eb7b64 --- /dev/null +++ b/changelog/cpp98.dd @@ -0,0 +1,56 @@ +Transition to C++11 character types + + With C++11 comes the advent of changed character type mangling. + D's default behavior is now to conform to this. However, this + will break existing code. Therefore, the old behavior can be + retained by using the -version=Cpp98 compiler switch. + For Win32 compilations using Digital Mars C++, -version=Cpp98 will + be predefined. + + Of particular note is the new difference between wchar and wchar_t on + Windows. This will manifest itself as compile errors when + interfacing wchar* with wchar_t* code when calling the Windows API. + A cast will resolve the issue. + + Going forward we recommend using WCHAR instead of wchar or wchar_t + when interfacing to Windows API functions. (WCHAR is Microsoft + Windows' 16 bit character type.) + + C++ Type Equivalence + + Cpp98 behavior: + + D Posix DMC++ Windows VC++ Windows + ---------------------------------------------------- + wchar unsigned short wchar_t wchar_t + dchar wchar_t unsigned unsigned + wchar_t wchar_t wchar_t wchar_t + WCHAR -- wchar_t wchar_t + + New behavior: + + D Posix DMC++ Windows VC++ Windows + ---------------------------------------------------- + wchar char16_t wchar_t char16_t + dchar char32_t unsigned char32_t + wchar_t wchar_t wchar wchar_t + WCHAR -- wchar wchar_t + + + Name Mangling: + + Cpp98 behavior: + + D Posix DMC++ Windows VC++ Windows + -------------------------------------------- + wchar t _Y _W + dchar w I I + wchar_t w _Y _W + + New behavior: + + Posix DMC++ Windows VC++ Windows + wchar Ds _Y _S + dchar Di I _U + wchar_t w _Y _W + diff --git a/src/dmd/cond.d b/src/dmd/cond.d index ef823db9abc1..189dc9de89c3 100644 --- a/src/dmd/cond.d +++ b/src/dmd/cond.d @@ -658,6 +658,7 @@ extern (C++) final class VersionCondition : DVCondition case "CppRuntime_Gcc": case "CppRuntime_Microsoft": case "CppRuntime_Sun": + case "Cpp98": case "unittest": case "assert": case "all": diff --git a/src/dmd/globals.d b/src/dmd/globals.d index 6e475694229e..5e5e24e13004 100644 --- a/src/dmd/globals.d +++ b/src/dmd/globals.d @@ -149,6 +149,7 @@ struct Param // https://issues.dlang.org/show_bug.cgi?id=16997 bool fixAliasThis; // if the current scope has an alias this, check it before searching upper scopes bool vsafe; // use enhanced @safe checking + bool cpp98; // follow C++98 type system issues rather than C++11 bool ehnogc; // use @nogc exception handling bool dtorFields; // destruct fields of partially constructed objects // https://issues.dlang.org/show_bug.cgi?id=14246 diff --git a/src/dmd/globals.h b/src/dmd/globals.h index 336deae5481c..43c1ba0b614e 100644 --- a/src/dmd/globals.h +++ b/src/dmd/globals.h @@ -123,7 +123,8 @@ struct Param bool fix16997; // fix integral promotions for unary + - ~ operators // https://issues.dlang.org/show_bug.cgi?id=16997 bool vsafe; // use enhanced @safe checking - bool ehnogc; // use @nogc exception handling + bool cpp98; // follow C++98 type system issues rather than C++11 + bool ehnogc; // use @nogc exception handling bool dtorFields; // destruct fields of partially constructed objects // https://issues.dlang.org/show_bug.cgi?id=14246 bool showGaggedErrors; // print gagged errors anyway diff --git a/src/dmd/mars.d b/src/dmd/mars.d index 8e70f9728a11..8b574aff3cb6 100644 --- a/src/dmd/mars.d +++ b/src/dmd/mars.d @@ -387,6 +387,8 @@ private int tryMain(size_t argc, const(char)** argv) global.params.useExceptions = false; } + if (global.params.isWindows && !global.params.mscoff) + global.params.cpp98 = true; // DMC++ is a C++98 compiler if (!global.params.obj || global.params.lib) global.params.link = false; @@ -1235,6 +1237,9 @@ void addDefaultVersionIdentifiers(const ref Param params) VersionCondition.addPredefinedGlobalIdent("D_Version2"); VersionCondition.addPredefinedGlobalIdent("all"); + if (params.cpp98) + VersionCondition.addPredefinedGlobalIdent("Cpp98"); + if (params.cpu >= CPU.sse2) { VersionCondition.addPredefinedGlobalIdent("D_SIMD"); @@ -2053,9 +2058,14 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param } else if (Identifier.isValidIdentifier(p + 9)) { - if (!params.versionids) - params.versionids = new Array!(const(char)*); - params.versionids.push(p + 9); + if (strcmp(p + 9, "Cpp98") == 0) // -version=Cpp98 + params.cpp98 = true; // version will be set in addDefaultVersionIdentifiers() + else + { + if (!params.versionids) + params.versionids = new Array!(const(char)*); + params.versionids.push(p + 9); + } } else goto Lerror;