template mixin function name mangling

Peter Alexander peter.alexander.au at gmail.com
Mon Apr 22 02:03:23 PDT 2013


On Sunday, 21 April 2013 at 21:43:03 UTC, John Colvin wrote:
> Apologies for another question so short after the previous one.
>
> tempmix.d:
>
> mixin template Foo()
> {
>     extern(C) void foo() {}
> }
>
> mixin Foo!();
>
> extern(C) void bar() {}
>
>
> $dmd -c tempmix.d
> $nm tempmix.o
> 0000000000000000 t
> 0000000000000000 T bar
> 0000000000000000 D _D7tempmix12__ModuleInfoZ
> 0000000000000000 T _D7tempmix15__unittest_failFiZv
> 0000000000000000 T _D7tempmix7__arrayZ
> 0000000000000000 T _D7tempmix8__assertFiZv
> 0000000000000000 W _D7tempmix8__T3FooZ3fooUZv
>                  U _d_array_bounds
>                  U _d_assertm
>                  w _d_dso_registry
>                  U _Dmodule_ref
>                  U _d_unittestm
>
> foo gets mangled D-style, bar is left bare. Is this deliberate? 
> I was under the impression that they should both be left bare.
>
> I tried moving the extern(C) around to various other places, 
> including extern(C): at the top of the file. No success.

Hmmm, not sure what should happen here. Seems to be an 
underspecified part of the language.

On a first glance, it would appear as a bug. foo should be mixed 
in as extern(C), just as if you had copied it there by hand, but 
problems arise with situations like this:

mixin template A() {
     extern(C) int foo() { return 1; }
}

mixin template B() {
     extern(C) int foo() { return 2; }
}

mixin A();
mixin B();

void main() {
     int x = A.foo() + B.foo();
}

If both foo's have the same symbol, then how am I able to 
disambiguate them in code?

Maybe duplicate extern(C) template mixin symbols need to be an 
error?


More information about the Digitalmars-d mailing list