[Issue 15372] New: DMD emits wrong mangling for extern(C++) free function templates

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Nov 22 00:18:08 PST 2015


https://issues.dlang.org/show_bug.cgi?id=15372

          Issue ID: 15372
           Summary: DMD emits wrong mangling for extern(C++) free function
                    templates
           Product: D
           Version: D2
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: jakobovrum at gmail.com

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

--


More information about the Digitalmars-d-bugs mailing list