Bug 15970 – C++ mangling of templated arg type

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2016-04-29T09:13:57Z
Last change time
2018-10-22T18:07:29Z
Keywords
C++, mangling
Assigned to
Guillaume Chatelet
Creator
Johan Engelen

Comments

Comment #0 by jbc.engelen — 2016-04-29T09:13:57Z
C++ mangling is wrong when a function takes an argument of type T (templated) and when the typeof(T) is a class. Test case: ``` extern(C++) class Symbol {} extern(C++) class Symbol2 {} extern(C++) class A(T) { void foo_template(T t) {} void foo_incorrect(Symbol t) {} void foo_correct(Symbol2 t) {} } A!int b_works; A!Symbol b_incorrect; ``` Then running > dmd -c cpp.d -ofcpp.o > nm cpp.o | c++filt gives the correct mangling for A!int: A<int>::foo_correct(Symbol2*) A<int>::foo_template(int) A<int>::foo_incorrect(Symbol*) but incorrect mangling for A!Symbol: A<Symbol*>::foo_correct(Symbol2*) A<Symbol*>::foo_template(A<Symbol*>) <--- argument type wrong A<Symbol*>::foo_incorrect(A<Symbol*>) <--- argument type wrong
Comment #1 by chatelet.guillaume — 2016-07-03T17:07:31Z
FYI this is mangled correctly in https://github.com/gchatelet/dmd/blob/new_cpp_mangling2. It is not yet ready to for a PR though.
Comment #2 by chatelet.guillaume — 2016-07-03T17:14:56Z
Comment #3 by bugzilla — 2017-11-01T08:35:22Z
In C++, class types are not reference types. In D they are, and D represents the reference type as a pointer type when translating to C++. The result is what you see, Symbol* instead of Symbol when looking at the C++ mangling. This is working as intended.
Comment #4 by jbc.engelen — 2017-11-01T10:43:45Z
Read the bug report carefully before discarding it. The argument type is currently "A<Symbol*>" (wrong), instead of "Symbol*"
Comment #5 by pro.mathias.lang — 2018-10-22T18:07:29Z
Marking as a duplicate of 16479, which is older, but for which there is a PR. I just tried it with PR 8455 and it gets mangled correctly: ``` ../../install/osx/bin/dmd -c lol.d; nm lol.o | c++filt [...] 00000000000004c8 S A<int>::foo_template(int) 0000000000000040 S A<int>::foo_template(int) (.eh) 00000000000004d0 S A<int>::foo_incorrect(Symbol*) 0000000000000068 S A<int>::foo_incorrect(Symbol*) (.eh) ``` *** This issue has been marked as a duplicate of issue 16479 ***