-
-
Notifications
You must be signed in to change notification settings - Fork 613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add -std=c++98 to compiler #9029
Conversation
Thanks for your pull request, @WalterBright! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#9029" |
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type system issues
type mangling rules?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little more than just mangling.
Looks otherwise OK, cc @ibuclaw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a precedent. We don't use -version
to enable some features so far.
E.g. all of those flags could possibly be enabled the same way, but we have a predefined switch each time.
Also this only adds a version identifier, but doesn't actually changes the mangling as the changelog advertises.
As noted, I see a discrepancy between changelog and patch as well. Shouldn't the new field be an enum to be future-proof? It was raised in the other PR that C++-20 will add |
I explained this in the top comment. |
It would be trivial to do that in the future if/when it becomes necessary. My experience with future proofing in the past is that future inevitably turns out different than anticipated, making ones attempts look silly. For example, look at the future proofing Microsoft did in windows.h. It was all done completely wrong. |
This was @andralex 's idea. I thought I'd run it up the flagpole and see if people like it. It provides a nice way to connect the two concepts, reduces the documentation necessary, and provides a way to add such without needing to continually invent more switches. |
a521909
to
17166c1
Compare
Blocking: dlang/druntime#2390 |
I don't like it either. It mixes two different things under one lid ( I suggest using a convention identical or similar to what C++ compilers use. gcc and clang use |
@CyberShadow you don't like it because you'd prefer to be compatible with the gcc/clang switches, or because you don't like the concept of using |
This comment has been minimized.
This comment has been minimized.
Compatibility (well, more familiarity) with gcc/clang is a bonus,.
c.f. the switches used to control the C standard library version. |
changelog/cpp98.dd
Outdated
wchar char16_t wchar_t char16_t | ||
dchar char32_t unsigned char32_t | ||
wchar_t wchar_t wchar wchar_t | ||
WCHAR -- wchar wchar_t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is wchar
in C++? There's no C++ type called wchar
that I'm aware of... Is it just a DMC thing?
Otherwise, this looks correct to me. And I completely endorse using WCHAR in Win32 API's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
changelog/cpp98.dd
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "old behaviour" is a better term to use than "Cpp98" behaviour, which feels misleading...
If we were implementing C++98 behaviour, shouldn't it look like this:
D Posix DMC++ Windows VC++ Windows
wchar ** ERROR: CAN'T MANGLE **
dchar ** ERROR: CAN'T MANGLE **
wchar_t wchar_t wchar_t wchar_t
WCHAR -- wchar_t wchar_t
?
There's one additional detail though; VC++ has a compiler option where you can choose to NOT mangle wchar_t
and instead it is a typedef for unsigned short
... I've seen code compiled that way, but not for over a decade. I recommend not making any concession for that deprecated case.
I guess the reason for that hack dates back to when people used C compilers with no mangling distinction, and in C, WCHAR
is a typedef for unsigned short
, so some C programmers used unsigned short
directly in their code, and hence the option in VC++ appeared to mangle for compatibility with those old programs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERROR: CAN'T MANGLE
But it can and does mangle them for C++98, per the chart.
I agree with not supporting the old VC++ switch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Manu is saying that D's wchar
and dchar
do not exist in C++98, which is why strictly speaking the table does not describe C++98 behavior, just the way DMD approached it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it can and does mangle them for C++98, per the chart.
But it's wrong, and it's always been wrong. There is no compatible mangling for wchar
or dchar
in C++. We've just been using an arbitrary (albeit practical) mapping.
I'm just saying that calling it "C++98" is misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wchar_t
is a keyword in C++98, and a distinct type, and has its own mangling. This is reflected in the chart, where wchar
uses the wchar_t
mangling for Windows, and dchar
uses the wchar_t
mangling for Posix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where wchar uses the wchar_t mangling for Windows, and dchar uses the wchar_t mangling for Posix.
wchar
and dchar
have no equivalent type in C++98. I think it's improper to map them to wchar_t
. I understand it's for backwards compatibility with legacy DMD behaviour, but what I'm saying is, I don't think it's correct to call that mapping "Cpp98", because that's not what it is... it's just a mapping that DMD implemented.
I would expect a mode called "C++98 compatibility" to issue a compile error on account of no counterpart type in the C++98 language. Same way we give compile errors for T[]
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wchar and dchar have no equivalent type in C++98.
Neither do any of the D basic types, not even int
. We just look for the most pragmatic mapping.
@WalterBright Thank you for getting involved on this issue. It will be nice to finally move on it! |
It less likely to happened with symbols in Phobos because of modules are creating a namespace. If you don't import the module with the new symbol there's no problem. This identifier is global. |
Version identifiers are in a separate symbol table from all other symbols. |
Using static / renamed imports is not really common practice in D. The problem still exists when an added symbol causes an ambiguous overload.
Probably, reserving a namespace for compiler-declared or internal version identifiers would have made sense, but it is probably too late now. Actually, we can still follow the convention of |
They've been in their own namespace since Day 1: https://github.com/dlang/dmd/blob/master/src/dmd/globals.d#L213 Debug identifiers are in their own namespace as well. |
I meant, a separate namespace from user-declared |
(I will assume the answer is nothing then).
|
Yes. But there are no namespaces for version identifiers. If I use the |
We can add -std=c++11 to the compiler and have the flag be the default when compiling code. |
I think it's a mistake for the default to not match the C++ compiler... otherwise you compile a I tried to point this out above... |
Which c++ compiler are we talking about here? What you are asking for is practically is impossible! My main concern on this PR is the lack of clarification codewise when introducing the -std=c++98 flag and not a flag for 11, 14, 17 and the upcoming 20. If we are going to mangle via a flag then there needs to be one for every official version of cpp. |
Unless your compiler is called gdc. :-) This is another point. Whatever proposed solution shouldn't make so that gdc is out of sync with the g++ compiler it is shipped with. I am very much aware of dmd's problem though, and that they tend to be 2 versions behind gcc because what is current compiler and what is the compiler installed on people's systems (Redhat, Ubuntu LTS) are two different things. |
You know I was referring to dmd here. :p |
I'm not following your logic. We should match the behavior of older versions of gcc, because..? As more time passes, there will be fewer and fewer users of old gcc, and more and more users of new versions. The only thing that makes sense is to match the default behavior of current compiler versions. Then, assuming that the C++ and D compiler a user has installed were released around the same time, they have the highest chance that everything will work by default. |
I am talking std flags here and why matching default flags of dmd with other c++ compilers is practically impossible, and not an issue that dmd needs to solve. |
I understood what you are talking about. I don't see how your arguments back up your suggestion, and you haven't replied to my arguments why I think your suggestion doesn't make sense. |
I have encounter programmers who are stuck with using old c++ compilers in their work place. Why they are stuck with it does not matter. What matter is that they exist and they NEED to be accountable, not assume that they will use the latest compiler.
As I said before:
Unless W&A write down the list of C++ compilers that dmd will support with regards to mangling , they still need to be taken into account.
The Latest Boost library still support certain old compilers. |
If the default is C++11 mode, then linking against code built with old compilers will not work unless you specify If the default is C++98 mode, then linking against code built with new compilers will not work unless you specify Why do you think we should care only about old compilers, and not new ones? |
How the heck do you reach that conclusion!? |
Right. So why do you think the default should be to support old compilers, when the number of their users will only shrink? |
My suggestion is to introduce the c++11 flag and have it be default for dmd. |
Regarding the defaults, I think sensible options exist; for GDC it should be the same as the GCC compiler of the same version. For LDC, some marriages make sense, like MSVC LDC can match MSVC's defaults sensibly. Or just throw it all into the wind! Either way, it's still a level, not a set of boolean flags. |
You still don't know which version of Xcode (the compiler) the user is running. For the latest version of Xcode, Apple only supports the two latest versions of macOS. If you're running an older version of macOS you cannot run the latest version of the compiler. DMD could in theory query the version of the compiler and adopt for that. |
Ok, the alternative has been merged. Is there any reason why this should remain open? |
I believe no, thanks for the reminder! |
The end result is as specified in cpp98.dd. However, all this PR does is add support for the -version=cpp98 switch, and the setting of the
global.params.cpp98
. It will be up to later PRs to change the name mangling in dmd and change thewchar_t
andWCHAR
aliases in druntime.