Bug 15372 – DMD emits wrong mangling for extern(C++) free function templates
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2015-11-22T08:18:00Z
Last change time
2016-10-01T11:44:42Z
Keywords
C++
Assigned to
nobody
Creator
jakobovrum
Comments
Comment #0 by jakobovrum — 2015-11-22T08:18:08Z
cppsrc/interop.cpp:
----
template<class T>
void foo()
{
}
void test()
{
foo<int>();
}
----
dsrc/interop.d:
----
extern(C++) void foo(T)();
void main()
{
foo!int();
}
----
Built with:
----
g++ -c cppsrc/interop.cpp --output=cpp_interop.o
dmd dsrc/interop.d cpp_interop.o
----
Output:
----
interop.o: In function `_Dmain':
dsrc/interop.d:(.text._Dmain+0x5): undefined reference to `foo<int>::foo()'
collect2: error: ld returned 1 exit status
--- errorlevel 1
----
nm --demangle cpp_interop.o:
----
0000000000000000 W void foo<int>()
0000000000000000 T test()
----
nm --demangle interop.o:
----
...
U foo<int>::foo()
...
----
nm cpp_interop.o:
----
0000000000000000 W _Z3fooIiEvv
0000000000000000 T _Z4testv
----
nm interop.o:
----
...
U _ZN3fooIiE3fooEv
...
----
Using g++ (GCC) 5.2.0 and DMD git head on Linux. Passing --std=c++11 when compiling the C++ code results in the same mangled names. Using -L-lstdc++ is of course not relevant here either.
This is an issue for https://github.com/D-Programming-Language/dlang.org/pull/1154