www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20679] New: C++ name mangling mismatch with templated return


          Issue ID: 20679
           Summary: C++ name mangling mismatch with templated return type
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: andrej.mitrovich gmail.com


#include <unordered_map>

template<typename K, typename V>
std::unordered_map<K, V>* cpp_unordered_map_create ()
    return new std::unordered_map<K, V>();

#define CPPUNORDEREDMAPCREATEINST(K, V) template std::unordered_map<K, V>*
cpp_unordered_map_create<K, V>();

import std.meta;

private template StdNS ()
    version (darwin)
        alias StdNS = AliasSeq!(`std`, `__1`);
        alias StdNS = AliasSeq!(`std`);

extern(C++, (StdNS!())) struct allocator (T) {}
extern(C++, (StdNS!())) struct pair (T1, T2) {}
extern(C++, (StdNS!())) struct hash (T) {}
extern(C++, (StdNS!())) struct equal_to (T = void) {}

extern(C++, (StdNS!()))
    struct unordered_map (Key, T, Hash = hash!Key, KeyEqual = equal_to!Key,
Allocator = allocator!(pair!(const Key, T)))
        void* ptr;

pure nothrow  nogc  safe extern(C++) unordered_map!(K, V)*
cpp_unordered_map_create (K, V)();

void main ()
    auto map = cpp_unordered_map_create!(int, int);

There seems to be an issue with substitution:

$ nm test.o | grep "cpp_unordered_map_create"

$ nm cpp.o | grep "cpp_unordered_map_create"

On the C++ side S1_ and S2_ are used in place of just 'i' for the two integer

Mar 17 2020