D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7925 - extern(C++) delegates?
Summary: extern(C++) delegates?
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: C++, industry, pull
Depends on:
Blocks:
 
Reported: 2012-04-16 09:08 UTC by Manu
Modified: 2021-11-30 13:43 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 Manu 2012-04-16 09:08:19 UTC
I really need a mechanism to perform C++ 'thiscall' calls. I think extern(C++) delegates seem the obvious way to do it in D.

The implementation would be nothing more than marked delegates simply calling with the 'thiscall' convention. I don't think it would have any affect at all on language semantics.

Without such a feature, I currently use proxy functions on both sides of the language barrier, which are a pain to maintain and very annoying when debugging (step in).
Comment 1 Manu 2018-06-04 08:28:26 UTC
As in https://issues.dlang.org/show_bug.cgi?id=18928, we have observed that C++ and D method calling convention is different (RVO expectations don't match).
This means delegates need to know their calling convention, otherwise they will call incorrectly for the function that's assigned to them.
I suggest `extern(C++) delegate` which would guarantee the delegate uses the appropriate C++ calling convention.
Comment 2 Dlang Bot 2021-10-23 14:10:44 UTC
@tim-dlang created dlang/dmd pull request #13217 "fix Issue 7925 - extern(C++) delegates" fixing this issue:

- fix Issue 7925 - extern(C++) delegates
  
  The linkage is already part of the type for delegates. Member functions
  for extern(C++) on Win32 use a different calling convention than other
  functions. This commit changes the calling convention of extern(C++)
  delegates for Win32 to match member functions. The calling convention
  for nested functions is also changed, because they can become delegates,
  too.

https://github.com/dlang/dmd/pull/13217
Comment 3 Dlang Bot 2021-11-30 13:43:36 UTC
dlang/dmd pull request #13217 "fix Issue 7925 - extern(C++) delegates" was merged into master:

- e6e1450f24691ef56892bddaaedbd0e677060de3 by Tim Schendekehl:
  fix Issue 7925 - extern(C++) delegates
  
  The linkage is already part of the type for delegates. Member functions
  for extern(C++) on Win32 use a different calling convention than other
  functions. This commit changes the calling convention of extern(C++)
  delegates for Win32 to match member functions. The calling convention
  for nested functions is also changed, because they can become delegates,
  too.

https://github.com/dlang/dmd/pull/13217