digitalmars.D - template mixin function name mangling
- John Colvin (26/26) Apr 21 2013 Apologies for another question so short after the previous one.
- Peter Alexander (21/47) Apr 22 2013 Hmmm, not sure what should happen here. Seems to be an
- Peter Alexander (7/12) Apr 22 2013 Oops, syntax fail. Should be something more like this:
- John Colvin (9/24) Apr 22 2013 If there are true duplicates then it would need to be an error.
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.
Apr 21 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?
Apr 22 2013
On Monday, 22 April 2013 at 09:03:24 UTC, Peter Alexander wrote:mixin A(); mixin B(); void main() { int x = A.foo() + B.foo(); }Oops, syntax fail. Should be something more like this: mixin A a; mixin B b; void main() { int x = a.foo() + b.foo(); }
Apr 22 2013
On Monday, 22 April 2013 at 09:03:24 UTC, Peter Alexander wrote:mixin template A() { extern(C) int foo() { return 1; } } mixin template B() { extern(C) int foo() { return 2; } } mixin A a; mixin B 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?If there are true duplicates then it would need to be an error. However, if a mixin uses a mixin identifier then it's going to need to be mangled anyway, so only mixin A; mixin B; would have to be an error. It already is an error, but unfortunately only when you reference the content of the mixin, not at the mixin statement.
Apr 22 2013