Hi

[template.cpp]:
template<typename Type>
void some_templated_function();

template<>
void some_templated_function<int>()
{}

[main.d]:
extern(C++) {
  void some_templated_function(Type)();
}

void main() {
  some_templated_function!int;
}

compilation:
g++ -c template_with_ns.cpp
dmd main.d template.o

this WORKS! :) BUT, now I put all c++ stuff into a namespace
[template_with_ns.cpp]:
namespace some_namespace {

template<typename Type>
void some_templated_function();

template<>
void some_templated_function<int>()
{}

}

[main_with_ns.d]:
extern(C++, some_namespace) {
  void some_templated_function(Type)();
}

void main() {
  some_templated_function!int;
}

DOES NOT compile
undefined reference to `void some_templated_function<int>()'

nm main_with_ns.o
_Z23some_templated_functionIiEvv
nm template_with_ns.o
_ZN14some_namespace23some_templated_functionIiEEvv

It seems like dmd doesn't care about the namespace of the template. Can someone confirm this as a bug? or am I doing something terrible wrong? :)

When I retry this with gdc it doesn't compile. Neither with namespace nor without:
nm template.o:
_Z23some_templated_functionIiEvv
main.o:
_ZN23some_templated_functionIiE23some_templated_functionEv

The more I work with D, interfacing C++, the more I start to know "mangling" :D

Have fun
Markus

Reply via email to