Bug 3211 – Template mix-ins silently drop LinkageAttribute(s)

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2009-07-26T04:03:00Z
Last change time
2014-04-18T09:12:07Z
Keywords
link-failure
Assigned to
nobody
Creator
komadori

Comments

Comment #0 by komadori — 2009-07-26T04:03:42Z
When a template is mixed-in, any LinkageAttribute(s) on functions inside its body are silently dropped. I believe this should not be the case. Reproduced with DMD 1.046 under Linux and LDC r1522 under Solaris. Test case and compiler output below: ... module Test; template Test(char[] N) { mixin("extern (C) void "~N~"();"); } mixin Test!("abort"); // Using a string mix-in directly works fine: // mixin("extern (C) void abort();"); void main() { abort(); } --- Test.o: In function `_Dmain': Test.d:(.text._Dmain+0x4): undefined reference to `_D4Test26__T4TestVG5aa5_61626f7274Z5abortUZv' collect2: ld returned 1 exit status --- errorlevel 1
Comment #1 by bugzilla — 2009-07-29T01:48:27Z
Simplifying the test case to: template Test(string N) { extern (C) void foo(int i, int j); } mixin Test!("abort"); void main() { foo(1,2); } compiling and obj2asming the result, we see that foo() has the C calling convention, but has the mangled name. The mangled name is necessary so that different instances of the template won't collide. C mangling is only done for module level globals. This is as designed and is not a bug.