Skip to content

Commit 17166c1

Browse files
committed
add -version=cpp98 to compiler
1 parent f35640a commit 17166c1

File tree

7 files changed

+84
-4
lines changed

7 files changed

+84
-4
lines changed

changelog/cpp98.dd

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## Transition to C++11 character types
2+
3+
With C++11 comes the advent of changed character type mangling.
4+
D's default behavior is now to conform to this. However, this
5+
will break existing code. Therefore, the old behavior can be
6+
retained by using the -version=Cpp98 compiler switch.
7+
For Win32 compilations using Digital Mars C++, -version=Cpp98 will
8+
be predefined.
9+
10+
Of particular note is the new difference between wchar and wchar_t on
11+
Windows. This will manifest itself as compile errors when
12+
interfacing wchar* with wchar_t* code when calling the Windows API.
13+
A cast will resolve the issue.
14+
15+
Going forward we recommend using WCHAR instead of wchar or wchar_t
16+
when interfacing to Windows API functions. (WCHAR is Microsoft
17+
Windows' 16 bit character type.)
18+
19+
### C++ Type Equivalence
20+
21+
#### Cpp98 behavior:
22+
23+
D Posix DMC++ Windows VC++ Windows
24+
25+
wchar unsigned short wchar_t wchar_t
26+
dchar wchar_t unsigned unsigned
27+
wchar_t wchar_t wchar_t wchar_t
28+
WCHAR -- wchar_t wchar_t
29+
30+
#### New behavior:
31+
32+
D Posix DMC++ Windows VC++ Windows
33+
34+
wchar char16_t wchar_t char16_t
35+
dchar char32_t unsigned char32_t
36+
wchar_t wchar_t wchar wchar_t
37+
WCHAR -- wchar wchar_t
38+
39+
40+
### Name Mangling:
41+
42+
#### Cpp98 behavior:
43+
44+
D Posix DMC++ Windows VC++ Windows
45+
46+
wchar t _Y _W
47+
dchar w I I
48+
wchar_t w _Y _W
49+
50+
#### New behavior:
51+
52+
D Posix DMC++ Windows VC++ Windows
53+
54+
wchar Ds _Y _S
55+
dchar Di I _U
56+
wchar_t w _Y _W
57+

src/dmd/cond.d

+1
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@ extern (C++) final class VersionCondition : DVCondition
658658
case "CppRuntime_Gcc":
659659
case "CppRuntime_Microsoft":
660660
case "CppRuntime_Sun":
661+
case "Cpp98":
661662
case "unittest":
662663
case "assert":
663664
case "all":

src/dmd/globals.d

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ struct Param
149149
// https://issues.dlang.org/show_bug.cgi?id=16997
150150
bool fixAliasThis; // if the current scope has an alias this, check it before searching upper scopes
151151
bool vsafe; // use enhanced @safe checking
152+
bool cpp98; // follow C++98 type system issues rather than C++11
152153
bool ehnogc; // use @nogc exception handling
153154
bool dtorFields; // destruct fields of partially constructed objects
154155
// https://issues.dlang.org/show_bug.cgi?id=14246

src/dmd/globals.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ struct Param
123123
bool fix16997; // fix integral promotions for unary + - ~ operators
124124
// https://issues.dlang.org/show_bug.cgi?id=16997
125125
bool vsafe; // use enhanced @safe checking
126-
bool ehnogc; // use @nogc exception handling
126+
bool cpp98; // follow C++98 type system issues rather than C++11
127+
bool ehnogc; // use @nogc exception handling
127128
bool dtorFields; // destruct fields of partially constructed objects
128129
// https://issues.dlang.org/show_bug.cgi?id=14246
129130
bool showGaggedErrors; // print gagged errors anyway

src/dmd/mars.d

+18-3
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,13 @@ private int tryMain(size_t argc, const(char)** argv)
387387
global.params.useExceptions = false;
388388
}
389389

390+
/* TEMPORARILY set this to true until the runtime library is updated,
391+
* in order to not leave the system in an unbuildable state.
392+
*/
393+
global.params.cpp98 = true;
394+
395+
if (global.params.isWindows && !global.params.mscoff)
396+
global.params.cpp98 = true; // DMC++ is a C++98 compiler
390397

391398
if (!global.params.obj || global.params.lib)
392399
global.params.link = false;
@@ -1235,6 +1242,9 @@ void addDefaultVersionIdentifiers(const ref Param params)
12351242
VersionCondition.addPredefinedGlobalIdent("D_Version2");
12361243
VersionCondition.addPredefinedGlobalIdent("all");
12371244

1245+
if (params.cpp98)
1246+
VersionCondition.addPredefinedGlobalIdent("Cpp98");
1247+
12381248
if (params.cpu >= CPU.sse2)
12391249
{
12401250
VersionCondition.addPredefinedGlobalIdent("D_SIMD");
@@ -2053,9 +2063,14 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param
20532063
}
20542064
else if (Identifier.isValidIdentifier(p + 9))
20552065
{
2056-
if (!params.versionids)
2057-
params.versionids = new Array!(const(char)*);
2058-
params.versionids.push(p + 9);
2066+
if (strcmp(p + 9, "Cpp98") == 0) // -version=Cpp98
2067+
params.cpp98 = true; // version will be set in addDefaultVersionIdentifiers()
2068+
else
2069+
{
2070+
if (!params.versionids)
2071+
params.versionids = new Array!(const(char)*);
2072+
params.versionids.push(p + 9);
2073+
}
20592074
}
20602075
else
20612076
goto Lerror;

test/fail_compilation/reserved_version.d

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ fail_compilation/reserved_version.d(206): Error: version identifier `CppRuntime_
105105
fail_compilation/reserved_version.d(207): Error: version identifier `CppRuntime_Gcc` is reserved and cannot be set
106106
fail_compilation/reserved_version.d(208): Error: version identifier `CppRuntime_Microsoft` is reserved and cannot be set
107107
fail_compilation/reserved_version.d(209): Error: version identifier `CppRuntime_Sun` is reserved and cannot be set
108+
fail_compilation/reserved_version.d(210): Error: version identifier `Cpp98` is reserved and cannot be set
108109
---
109110
*/
110111

@@ -216,6 +217,7 @@ version = CppRuntime_DigitalMars;
216217
version = CppRuntime_Gcc;
217218
version = CppRuntime_Microsoft;
218219
version = CppRuntime_Sun;
220+
version = Cpp98;
219221

220222
// This should work though
221223
debug = DigitalMars;
@@ -300,6 +302,7 @@ debug = CppRuntime_DigitalMars;
300302
debug = CppRuntime_Gcc;
301303
debug = CppRuntime_Microsoft;
302304
debug = CppRuntime_Sun;
305+
debug = Cpp98;
303306
debug = D_Coverage;
304307
debug = D_Ddoc;
305308
debug = D_InlineAsm_X86;

test/fail_compilation/reserved_version_switch.d

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
// REQUIRED_ARGS: -version=CppRuntime_Gcc
8383
// REQUIRED_ARGS: -version=CppRuntime_Microsoft
8484
// REQUIRED_ARGS: -version=CppRuntime_Sun
85+
// REQUIRED_ARGS: -version=Cpp98
8586
// REQUIRED_ARGS: -version=D_Coverage
8687
// REQUIRED_ARGS: -version=D_Ddoc
8788
// REQUIRED_ARGS: -version=D_InlineAsm_X86
@@ -178,6 +179,7 @@
178179
// REQUIRED_ARGS: -debug=CppRuntime_Gcc
179180
// REQUIRED_ARGS: -debug=CppRuntime_Microsoft
180181
// REQUIRED_ARGS: -debug=CppRuntime_Sun
182+
// REQUIRED_ARGS: -debug=Cpp98
181183
// REQUIRED_ARGS: -debug=D_Coverage
182184
// REQUIRED_ARGS: -debug=D_Ddoc
183185
// REQUIRED_ARGS: -debug=D_InlineAsm_X86

0 commit comments

Comments
 (0)