Comment #0 by ellery-newcomer — 2014-04-13T21:44:14Z
the code:
mixin template T() {
extern(C) void fizzle();
}
mixin T!();
void main(){
fizzle();
}
the [unexpected] fireworks:
$ dmd error3
error3.o: In function `_Dmain':
error3.d:(.text._Dmain+0x5): undefined reference to `_D6error38__mixin46fizzleUZv'
Was hoping for
undefined reference to `fizzle'
Comment #1 by andrej.mitrovich — 2014-04-21T19:05:01Z
Technically they are part of a "namespace", since you can disambiguate them:
-----
mixin template T1()
{
extern(C) void fizzle() { }
}
mixin template T2()
{
extern(C) void fizzle() { }
}
mixin T1!() t1;
mixin T2!() t2;
void main()
{
t1.fizzle();
t2.fizzle();
}
-----
So I guess that's why they're mangled. As a workaround you can use this:
-----
mixin template T()
{
// or just pragma(mangle, "fizzle"), but this will at least error if
// you change the function name
pragma(mangle, __traits(identifier, fizzle))
extern(C) void fizzle();
}
mixin T!();
void main()
{
fizzle();
}
-----
Comment #2 by atila.neves — 2016-03-28T12:38:21Z
The problem with this workaround is that it fails for `extern(C++)` unless you use `pragma(mangle, ` with the exact same mangling.
Comment #3 by dkorpel — 2019-07-25T14:51:03Z
*** This issue has been marked as a duplicate of issue 962 ***