Skip to content

Commit

Permalink
Merge pull request #3908 from WalterBright/mangleVector
Browse files Browse the repository at this point in the history
better C++ std mangling
  • Loading branch information
andralex committed Aug 27, 2014
2 parents 6255bf1 + 7cef6e7 commit 1f8280c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/cppmangle.c
Expand Up @@ -394,6 +394,13 @@ class CppMangleVisitor : public Visitor
buf.insert(3, "Sa", 2);
}

// Replace ::std with St
if (buf.offset >= 7 && memcmp(buf.data, "_ZN3std", 7) == 0)
{
buf.remove(3, 4);
buf.insert(3, "St", 2);
}

if (d->isDtorDeclaration())
{
buf.writestring("D1");
Expand Down
30 changes: 18 additions & 12 deletions test/runnable/cppa.d
Expand Up @@ -389,8 +389,6 @@ version (linux)

extern (C++, std)
{
struct vector(T, A = allocator!T) { }

struct allocator(T)
{
version (linux)
Expand All @@ -400,27 +398,29 @@ extern (C++, std)
{ (cast(__gnu_cxx.new_allocator!T*)&this).deallocate(p, sz); }
}
}

version (linux)
{
class vector(T, A = allocator!T)
{
final void push_back(ref const T);
}
}
}

extern (C++)
{
version (linux)
void foo14(std.vector!(int)* p);
version (OSX)
void foo14(std.vector!(int)* p);
version (FreeBSD)
void foo14(std.vector!(int)* p);
void foo14(std.vector!(int) p);
}

void test14()
{
std.vector!int* p;
version (linux)
{
std.vector!int p;
foo14(p);
version (OSX)
foo14(p);
version (FreeBSD)
foo14(p);
}
}

version (linux)
Expand All @@ -429,6 +429,12 @@ version (linux)
{
pa.deallocate(null, 0);
}

void gun(std.vector!int pa)
{
int x = 42;
pa.push_back(x);
}
}

/****************************************/
Expand Down
3 changes: 3 additions & 0 deletions test/runnable/extra-files/cppb.cpp
Expand Up @@ -281,16 +281,19 @@ size_t getoffset13161a()
/****************************************************/

#if __linux__ || __APPLE__ || __FreeBSD__
#include <memory>
#include <vector>

#if __linux__
template struct std::allocator<int>;
template struct std::vector<int>;

void foo15()
{
std::allocator<int>* p;
p->deallocate(0, 0);
}

#endif

// _Z5foo14PSt6vectorIiSaIiEE
Expand Down

0 comments on commit 1f8280c

Please sign in to comment.