D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13932 - c++ mangling for template negative int parameter
Summary: c++ mangling for template negative int parameter
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Mac OS X
: P1 normal
Assignee: No Owner
URL:
Keywords: link-failure, pull
Depends on:
Blocks:
 
Reported: 2015-01-04 13:52 UTC by Steven Schveighoffer
Modified: 2015-02-18 03:41 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Steven Schveighoffer 2015-01-04 13:52:56 UTC
When linking with C++ code that uses a negative integer as a template parameter, D will fail to link because it outputs e.g. '-1' instead of 'n1' as required by ABI.

Example:

C++:

template <int x> struct S
{
    int member;
};

void func(S<-1> s) {}

D:

struct S(int x)
{
    int member;
}

extern(C++) void func(S!(-1) s);

void main()
{
    func(S!(-1)(0));
}

result:

Undefined symbols for architecture x86_64:
  "__Z4func1SILi-1EE", referenced from:
      __Dmain in testcpp1.o

I don't know what platforms other than OSX this causes a problem on.

I am working on a pull that fixes this, will post soon.
Comment 1 Steven Schveighoffer 2015-01-04 17:49:45 UTC
PR: https://github.com/D-Programming-Language/dmd/pull/4239
Comment 2 github-bugzilla 2015-01-05 15:05:11 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/d60b61437081f3cb1b586af05c1507f1c304753c
More proper implementation for parse error on version and debug.
Fix issue 13932 -- c++ mangling for template negative int parameter
add test case for 13932

https://github.com/D-Programming-Language/dmd/commit/85946f3400b4afdb0a664064c4c79fe3218611bc
Fix issue 13932 on Windows as well.