diff --git a/src/cppmangle.d b/src/cppmangle.d index 9c9763e94ac0..f70f516f34fc 100644 --- a/src/cppmangle.d +++ b/src/cppmangle.d @@ -119,7 +119,7 @@ static if (TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TAR if (!skipname && !substitute(ti.tempdecl)) { store(ti.tempdecl); - const(char)* name = ti.toAlias().ident.toChars(); + const(char)* name = ti.tempdecl.toAlias().ident.toChars(); buf.printf("%d%s", strlen(name), name); } buf.writeByte('I'); @@ -429,7 +429,9 @@ static if (TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TAR TypeFunction tf = cast(TypeFunction)d.type; buf.writestring("_Z"); Dsymbol p = d.toParent(); - if (p && !p.isModule() && tf.linkage == LINKcpp) + TemplateDeclaration ftd = getFuncTemplateDecl(d); + + if (p && !p.isModule() && tf.linkage == LINKcpp && !ftd) { buf.writeByte('N'); if (d.type.isConst()) @@ -469,6 +471,13 @@ static if (TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TAR } buf.writeByte('E'); } + else if (ftd) + { + source_name(p); + this.is_top_level = true; + tf.nextOf().accept(this); + this.is_top_level = false; + } else { source_name(d); diff --git a/test/compilable/test15802.d b/test/compilable/test15802.d new file mode 100644 index 000000000000..9566eab6d9b6 --- /dev/null +++ b/test/compilable/test15802.d @@ -0,0 +1,10 @@ +extern(C++) { + template Foo(T) { + static int boo(); + } +} + +void main() +{ + string s = Foo!(int).boo.mangleof; +} diff --git a/test/runnable/cppa.d b/test/runnable/cppa.d index 80371a2edb0d..46a9df1c518a 100644 --- a/test/runnable/cppa.d +++ b/test/runnable/cppa.d @@ -1084,6 +1084,35 @@ void test15610() c.f(); } +/****************************************/ +// 15372 + +extern(C++) int foo15372(T)(T v); + +void test15372() +{ + version(Windows){} + else + assert(foo15372!int(1) == 1); +} + +/****************************************/ +// 15802 + +extern(C++) { + template Foo15802(T) { + static int boo(T v); + } +} + +void test15802() +{ + version(Windows){} + else + assert(Foo15802!(int).boo(1) == 1); +} + + /****************************************/ void main() @@ -1123,6 +1152,8 @@ void main() testeh3(); test15579(); test15610(); + test15372(); + test15802(); printf("Success\n"); } diff --git a/test/runnable/extra-files/cppb.cpp b/test/runnable/extra-files/cppb.cpp index 4ce847e90bd3..e948ad359613 100644 --- a/test/runnable/extra-files/cppb.cpp +++ b/test/runnable/extra-files/cppb.cpp @@ -695,4 +695,32 @@ void Derived2::f() } /******************************************/ +// 15372 +template +int foo15372(int value) +{ + return value; +} + +void test15372b() +{ + int t = foo15372(1); +} + +/****************************************/ +// 15802 +template +class Foo15802 +{ +public: + static int boo(int value) + { + return value; + } +}; + +void test15802b() +{ + int t = Foo15802::boo(1); +}