Permalink
Browse files

Issue 5718 - Can't demangle symbol defined inside unittest block

std.traits.mangledName should return valid mangled name against symbols in function.
  • Loading branch information...
9rnsr committed Feb 1, 2012
1 parent 7ccab2a commit 686f53f6d2d373ad13ea854b52e924fd7030422f
Showing with 21 additions and 2 deletions.
  1. +21 −2 std/traits.d
View
@@ -3575,7 +3575,15 @@ pragma(msg, mangledName!(C.value)); // prints "_D4test1C5valueMFNdZi"
template mangledName(sth...)
if (sth.length == 1)
{
enum string mangledName = removeDummyEnvelope(Dummy!(sth).Hook.mangleof);
static if (is(typeof(sth[0]) X) && is(X == void))
{
// sth[0] is a template symbol
enum string mangledName = removeDummyEnvelope(Dummy!(sth).Hook.mangleof);
}
else
{
enum string mangledName = sth[0].mangleof;
}
}
private template Dummy(T...) { struct Hook {} }
@@ -3641,7 +3649,18 @@ unittest
static assert(mangledName!(removeDummyEnvelope) ==
"_D3std6traits19removeDummyEnvelopeFAyaZAya");
int x;
static assert(mangledName!((int a) { return a+x; })[$ - 9 .. $] == "MFNbNfiZi"); // nothrow safe
static assert(mangledName!((int a) { return a+x; }) == "DFNbNfiZi"); // nothrow safe
}
unittest
{
// Test for bug 5718
import std.demangle;
int foo;
assert(demangle(mangledName!foo)[$-7 .. $] == "int foo");
void bar(){}
assert(demangle(mangledName!bar)[$-10 .. $] == "void bar()");
}

0 comments on commit 686f53f

Please sign in to comment.