Thread overview
pragma(mangle, on a template)
Aug 17, 2015
Freddy
Aug 17, 2015
Adam D. Ruppe
Aug 17, 2015
Freddy
Aug 17, 2015
BBasile
August 17, 2015
I can't get pragma(mangle) to work on templates(or structs).
----
import std.stdio;

struct MyStruct(T...)
{
    int var;
    void func()
    {
        writeln(var);
    }
}

pragma(mangle, "MyAlias") alias MyAlias = MyStruct!("a", "b", "c" /+very long symbol bloating list+/ );

void main()
{
    auto v = MyAlias(2);
    v.func();
}
----
August 17, 2015
On Monday, 17 August 2015 at 02:46:02 UTC, Freddy wrote:
> pragma(mangle, "MyAlias") alias MyAlias = MyStruct!("a", "b", "c" /+very long symbol bloating list+/ );

Mangling is done at a different level in the compiler than aliases, so I don't think this is intended to work.
August 17, 2015
On Monday, 17 August 2015 at 03:14:16 UTC, Adam D. Ruppe wrote:
> On Monday, 17 August 2015 at 02:46:02 UTC, Freddy wrote:
> Mangling is done at a different level in the compiler than aliases, so I don't think this is intended to work.
Is there any way I can mangle a template struct then?
August 17, 2015
On Monday, 17 August 2015 at 02:46:02 UTC, Freddy wrote:
> I can't get pragma(mangle) to work on templates(or structs).
> [...]

I don't know why but it looks like it only works on functions. Even if a struct is not a template the custom symbol mangle won't be handled:

---
import std.stdio;

pragma(mangle, "a0") class MyClass{}
pragma(mangle, "a1") struct MyStruct{}
pragma(mangle, "a2") void body_func();
pragma(mangle, "a3") struct MyStructh
    { pragma(mangle, "a4") void foo(){}}

void main()
{
    writeln(MyClass.mangleof);
    writeln(MyStruct.mangleof);
    writeln(body_func.mangleof);
    writeln(MyStructh.mangleof);
    writeln(MyStructh.foo.mangleof);
}
---

which outputs:

---
C13temp_019455687MyClass
S13temp_019455688MyStruct
a2
S13temp_019455689MyStructh
a4
---

'a4' being printed and not 'a3' is interesting BTW ;)
I think that the manual is not clear enough about this pragma:

http://dlang.org/pragma.html#mangle

Unless the spec. are more detailed this could be considered as a bug.