Issue 15372 - DMD emits wrong mangling for extern(C++) free function templates
Summary: DMD emits wrong mangling for extern(C++) free function templates
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Linux
: P1 normal
Assignee: No Owner
URL:
Keywords: C++
Depends on:
Blocks:
 
Reported: 2015-11-22 08:18 UTC by Jakob Ovrum
Modified: 2016-10-01 11:44 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jakob Ovrum 2015-11-22 08:18:08 UTC
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