Issue 12575 - extern(C) mangling ignored inside mixin template
Summary: extern(C) mangling ignored inside mixin template
Status: RESOLVED DUPLICATE of issue 962
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords: mangling
Depends on:
Blocks:
 
Reported: 2014-04-13 21:44 UTC by Ellery Newcomer
Modified: 2019-07-25 14:51 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Ellery Newcomer 2014-04-13 21:44:14 UTC
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 Andrej Mitrovic 2014-04-21 19:05:01 UTC
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 Atila Neves 2016-03-28 12:38:21 UTC
The problem with this workaround is that it fails for `extern(C++)` unless you use `pragma(mangle, ` with the exact same mangling.
Comment 3 Dennis 2019-07-25 14:51:03 UTC

*** This issue has been marked as a duplicate of issue 962 ***