Bug 14956 – C++ Mangling incompatible with C++11

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2015-08-24T15:07:09Z
Last change time
2022-03-01T01:46:38Z
Keywords
C++, mangling
Assigned to
No Owner
Creator
Iain Buclaw

Comments

Comment #0 by ibuclaw — 2015-08-24T15:07:09Z
DMD cannot link with C++ code compiled with GCC-5 because the mangling of the mangling for basic_string has changed. Reference: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html Affects the following tests: extern(C++) { void foo14a(std.basic_string!(char) *p); void foo14b(std.basic_string!(int) *p); void foo14f(std.char_traits!char* x, std.basic_string!char* p, std.basic_string!char* q); } Before (C++-98): _Z6foo14aPSs _Z6foo14bPSbIiSt11char_traitsIiESaIiEE _Z6foo14fPSt11char_traitsIcEPSsS2_ After (C++-11): _Z6foo14aPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE _Z6foo14bPNSt7__cxx1112basic_stringIiSt11char_traitsIiESaIiEEE _Z6foo14fPSt11char_traitsIcEPNSt7__cxx1112basic_stringIcS0_SaIcEEES6_
Comment #1 by ibuclaw — 2015-10-23T11:57:47Z
Ubuntu 15.10 has been released, and comes with gcc-5.2 as the default compiler. So as more developers upgrade, the more likely they are to notice that D2 testsuite no longer passes (or whatever C++ interop they are using in their program starts failing).
Comment #2 by Marco.Leise — 2015-10-27T09:25:45Z
The mangling of the mangling changed? I thought that was a typo, but obviously you are right. They mangled and wrapped the mangling into a __cxx11 wrapper. I assume the only way out of this is providing a -cxx11 flag for dmd? >.<
Comment #3 by ibuclaw — 2015-11-07T09:28:56Z
(In reply to Marco Leise from comment #2) > The mangling of the mangling changed? I thought that was a typo, but > obviously you are right. The C++-98 use of "Sb" and "Ss" is a special mangle string, and not actually representative of the actual name or namespace of basic_string. Perhaps a better way of putting it would have been: "The abbreviations for mangling basic_string have been removed and replaced with a new namespace".
Comment #4 by ibuclaw — 2015-11-07T09:37:45Z
(In reply to Marco Leise from comment #2) > I assume the only way out of this is providing a -cxx11 flag for dmd? >.< As we already support C++ namespaces, we can funnel what needs to be changed in the testsuite case itself. --- extern (C++, std) { version (C++-98) { struct basic_string(T, C = char_traits!T, A = allocator!T) { } } else version (C++-11) { extern (C++, __cxx11) { struct basic_string(T, C = char_traits!T, A = allocator!T) { } } } } --- Which leaves us with the question, how do figure out whether to use version condition branch A or B?
Comment #5 by doob — 2015-11-07T17:04:30Z
(In reply to Iain Buclaw from comment #4) > Which leaves us with the question, how do figure out whether to use version > condition branch A or B? The user specifies the appropriate version flag. Or the compiler need a new flag for this.
Comment #6 by ibuclaw — 2015-11-07T17:12:55Z
(In reply to Jacob Carlborg from comment #5) > (In reply to Iain Buclaw from comment #4) > > > Which leaves us with the question, how do figure out whether to use version > > condition branch A or B? > > The user specifies the appropriate version flag. Or the compiler need a new > flag for this. Well, so far, apart from the testsuite, is there any other place this is necessary? Probably not. We don't maintain a core.stdcxx library, thank goodness. And those who wish to use bindings to C++ std, then they can make the change in their code and provide some user defined version to select one or the other. I've only found one bug that prevents this. I've raised a PR for that. https://github.com/D-Programming-Language/dmd/pull/5261
Comment #7 by github-bugzilla — 2015-11-28T15:37:20Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/574542fe2cf83dc32ce59fd82631184de91ef2a5 Merge pull request #5262 from ibuclaw/issue14956b [14965]: Add versioned-out branch to support new C++-11 implementations of std::string
Comment #8 by github-bugzilla — 2016-01-03T14:02:34Z
Comment #9 by github-bugzilla — 2016-02-13T22:29:09Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f9b657b5fdca5658b4808fe444281fa4df23250a Merge pull request #5261 from ibuclaw/issue14956a Parameter types should have namespace std mangling too
Comment #10 by sahmi.soulaimane — 2017-05-09T05:56:42Z
I would like to point out that the __cxx11 namespace is not the only problem, infact there is another non trivial problem is the abi_tag used on functions that return a std::basic_string. for exaplme the following function: ``` std::base_string!char func() {} ``` will get the (demangled) name "func[cxx11]()", and there is actually no way of representing that in D.
Comment #11 by bugzilla — 2017-11-01T08:56:29Z
I'm not sure this is actually a D compiler problem. If, on the D side, basic_string is aliased to __cxx11::basic_string, it should mangle correctly. This is pointed out in Comment 4.
Comment #12 by bugzilla — 2017-11-01T08:58:01Z
(In reply to Sahmi Soulaïman (سليمان السهمي) from comment #10) > std::base_string!char func() {} The code is neither C++ nor D. Please provide an accurate code example, what it mangles to, and what it should mangle to. Thanks!
Comment #13 by sahmi.soulaimane — 2017-11-10T15:05:04Z
(In reply to Walter Bright from comment #12) > The code is neither C++ nor D. Please provide an accurate code example, what > it mangles to, and what it should mangle to. Thanks! example: --- #include <string> std::string toString(char* s) { return s; } --- The function "toString" above returns `std::string`, thus mangles to: "_Z8toStringB5cxx11Pc", which is in demangled form: "toString[abi:cxx11](char*)". The question is: how to emulate the "[abi:cxx11]" part of the mangling in d? Thanks!
Comment #14 by sahmi.soulaimane — 2019-06-08T16:26:32Z
I opened a dedicated issue for the abi_tag: issue #19949.
Comment #15 by iamthewilsonator — 2022-03-01T01:46:38Z
This has since been fixed