Skip to content

Commit aaadbc5

Browse files
committed
add -std=c++98 to compiler
1 parent 42040ba commit aaadbc5

File tree

8 files changed

+98
-1
lines changed

8 files changed

+98
-1
lines changed

changelog/cpp98.dd

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

src/dmd/cli.d

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,14 @@ dmd -cov -unittest myprog.d
561561
`$(UNIX Generate shared library)
562562
$(WINDOWS Generate DLL library)`,
563563
),
564+
Option("std=<standard>",
565+
"set compatiblity with <standard>",
566+
"Standards supported are:
567+
$(UL
568+
$(LI $(I c++98): Use older C++98 name mangling,
569+
Predefines `Cpp98` $(LINK2 $(ROOT_DIR)spec/version.html#predefined-versions, version))
570+
)",
571+
),
564572
Option("transition=<id>",
565573
"help with language change identified by 'id'",
566574
`Show additional info about language change identified by $(I id)`,

src/dmd/cond.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ extern (C++) final class VersionCondition : DVCondition
664664
case "CppRuntime_Gcc":
665665
case "CppRuntime_Microsoft":
666666
case "CppRuntime_Sun":
667+
case "Cpp98":
667668
case "unittest":
668669
case "assert":
669670
case "all":

src/dmd/globals.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,14 @@ struct Param
148148
bool fix16997; // fix integral promotions for unary + - ~ operators
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
151+
151152
/** The --transition=safe switch should only be used to show code with
152153
* silent semantics changes related to @safe improvements. It should not be
153154
* used to hide a feature that will have to go through deprecate-then-error
154155
* before becoming default.
155156
*/
156157
bool vsafe; // use enhanced @safe checking
158+
bool cpp98; // follow C++98 type system issues rather than C++11
157159
bool ehnogc; // use @nogc exception handling
158160
bool dtorFields; // destruct fields of partially constructed objects
159161
// https://issues.dlang.org/show_bug.cgi?id=14246

src/dmd/globals.h

Lines changed: 2 additions & 1 deletion
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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,9 @@ void addDefaultVersionIdentifiers(const ref Param params)
11221122
VersionCondition.addPredefinedGlobalIdent("D_Version2");
11231123
VersionCondition.addPredefinedGlobalIdent("all");
11241124

1125+
if (params.cpp98)
1126+
VersionCondition.addPredefinedGlobalIdent("Cpp98");
1127+
11251128
if (params.cpu >= CPU.sse2)
11261129
{
11271130
VersionCondition.addPredefinedGlobalIdent("D_SIMD");
@@ -2054,6 +2057,10 @@ bool parseCommandLine(const ref Strings arguments, const size_t argc, ref Param
20542057
params.manual = true;
20552058
return false;
20562059
}
2060+
else if (arg == "-std=c++98") // https://dlang.org/dmd.html#switch-std
2061+
{
2062+
params.cpp98 = true;
2063+
}
20572064
else if (arg == "-run") // https://dlang.org/dmd.html#switch-run
20582065
{
20592066
params.run = true;
@@ -2190,6 +2197,14 @@ private void reconcileCommands(ref Param params, size_t numSrcFiles)
21902197
params.useExceptions = false;
21912198
}
21922199

2200+
/* TEMPORARILY set this to true until the runtime library is updated,
2201+
* in order to not leave the system in an unbuildable state.
2202+
*/
2203+
params.cpp98 = true;
2204+
2205+
if (params.isWindows && !params.mscoff)
2206+
params.cpp98 = true; // DMC++ is a C++98 compiler
2207+
21932208

21942209
if (!params.obj || params.lib)
21952210
params.link = false;

test/fail_compilation/reserved_version.d

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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
@@ -279,6 +281,7 @@ Error: version identifier `CppRuntime_DigitalMars` is reserved and cannot be set
279281
Error: version identifier `CppRuntime_Gcc` is reserved and cannot be set
280282
Error: version identifier `CppRuntime_Microsoft` is reserved and cannot be set
281283
Error: version identifier `CppRuntime_Sun` is reserved and cannot be set
284+
Error: version identifier `Cpp98` is reserved and cannot be set
282285
Error: version identifier `D_Coverage` is reserved and cannot be set
283286
Error: version identifier `D_Ddoc` is reserved and cannot be set
284287
Error: version identifier `D_InlineAsm_X86` is reserved and cannot be set

0 commit comments

Comments
 (0)