www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3211] New: Template mix-ins silently drop LinkageAttribute(s)

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3211

           Summary: Template mix-ins silently drop LinkageAttribute(s)
           Product: D
           Version: unspecified
          Platform: x86
        OS/Version: All
            Status: NEW
          Keywords: link-failure
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: komadori gekkou.co.uk


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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 26 2009
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3211


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |INVALID





01:48:27 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 29 2009