New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Feb 1, 2012
Jump to file or symbol
Failed to load files and symbols.
+21 −2
Diff settings

Always

Just for now

Copy path View file
@@ -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;
}
}

This comment has been minimized.

@donc

donc Feb 1, 2012

Collaborator

Just as an aside, I'm certain that I wrote the original version of that code. It was originally called "mangleNameOf", and was published on the ng and in DDL project on dsource. Somebody copied it verbatim and republished it another dsource project with my name removed and most of the comments stripped out, but with the function names unchanged. I think this code is based on that. This code still doesn't include the comments explaining why it works, and it really needs to. It took a lot of creativity to come up with, it's really not obvious.

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()");
}
ProTip! Use n and p to navigate between commits in a pull request.