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 by turkeyman — 2018-06-04T08:28:26Z
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 by dlang-bot — 2021-10-23T14:10:44Z
@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 by dlang-bot — 2021-11-30T13:43:36Z
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