www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - C++ function signature template parameter mangling issue

reply Benjamin Thaut <code benjamin-thaut.de> writes:
I have a c++ struct:

template <typename retval>
struct ezDelegate<retval ()>
{
}

void DelegateTest(ezDelegate<void ()> func) { ... }

And I want to match that on the D side, unfortunately it does not work:

D:
struct ezDelegate(Signature) {}

alias delegate_t = ezDelegate!(void function());

extern(C++) void DelegateTest(delegate func);

D mangles
?DelegateTest  YAXU?$ezDelegate $$A6AXXZ   Z
void __cdecl DelegateTest(struct ezDelegate<void (__cdecl*)(void)>)

What C++ does:
?DelegateTest  YAXU?$ezDelegate P6AXXZ   Z
void __cdecl DelegateTest(struct ezDelegate<void __cdecl(void)>)

I understand that "void function()" is actually a function pointer and 
thus the mangling is "correct". But in what way would you actually able 
to mirror the C++ declaration of ezDelegate? Does it even work? This 
would be a central part of my interop with C++ so making it work would 
be nice.

Kind Regards
Benjamin Thaut
Feb 16 2015
parent reply "Daniel Murphy" <yebbliesnospam gmail.com> writes:
"Benjamin Thaut"  wrote in message news:mbtena$2n46$1 digitalmars.com... 

 I understand that "void function()" is actually a function pointer and 
 thus the mangling is "correct". But in what way would you actually able 
 to mirror the C++ declaration of ezDelegate? Does it even work? This 
 would be a central part of my interop with C++ so making it work would 
 be nice.
struct X(T) { pragma(msg, X.stringof); } void main() { X!(typeof(*(void function()).init)) x; }
Feb 16 2015
parent reply Benjamin Thaut <code benjamin-thaut.de> writes:
Am 17.02.2015 um 02:21 schrieb Daniel Murphy:
 struct X(T) { pragma(msg, X.stringof); }

 void main()
 {
     X!(typeof(*(void function()).init)) x;
 }
Error: ICE: Unsupported type void() So close...
Feb 16 2015
next sibling parent reply "Daniel Murphy" <yebbliesnospam gmail.com> writes:
"Benjamin Thaut"  wrote in message news:mbuok2$pn5$1 digitalmars.com...

 Error: ICE: Unsupported type void()

 So close...
Good news is that that's a compiler bug and not a language limitation. Although allowing you to pass a function type to a template in the first place might also be a compiler bug. D/C++ interop really works best when you can massage the C++ side a little.
Feb 16 2015
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 2/16/2015 11:42 PM, Daniel Murphy wrote:
 "Benjamin Thaut"  wrote in message news:mbuok2$pn5$1 digitalmars.com...

 Error: ICE: Unsupported type void()

 So close...
Good news is that that's a compiler bug and not a language limitation. Although allowing you to pass a function type to a template in the first place might also be a compiler bug. D/C++ interop really works best when you can massage the C++ side a little.
True, it might be easier to adjust the C++ side so it takes a pointer to a function type.
Feb 17 2015
parent "Benjamin Thaut" <code benjamin-thaut.de> writes:
On Tuesday, 17 February 2015 at 08:16:37 UTC, Walter Bright wrote:
 True, it might be easier to adjust the C++ side so it takes a 
 pointer to a function type.
In this case it would be really ugly ezDelegate<void()> vs ezDelegate<void(*)()> I will do a pull request later today fixing this mangling issue.
Feb 17 2015
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 2/16/2015 10:54 PM, Benjamin Thaut wrote:
 Am 17.02.2015 um 02:21 schrieb Daniel Murphy:
 struct X(T) { pragma(msg, X.stringof); }

 void main()
 {
     X!(typeof(*(void function()).init)) x;
 }
Error: ICE: Unsupported type void() So close...
Please file bugzilla!
Feb 17 2015
parent reply Benjamin Thaut <code benjamin-thaut.de> writes:
Am 17.02.2015 um 09:13 schrieb Walter Bright:
 On 2/16/2015 10:54 PM, Benjamin Thaut wrote:
 Am 17.02.2015 um 02:21 schrieb Daniel Murphy:
 struct X(T) { pragma(msg, X.stringof); }

 void main()
 {
     X!(typeof(*(void function()).init)) x;
 }
Error: ICE: Unsupported type void() So close...
Please file bugzilla!
https://issues.dlang.org/show_bug.cgi?id=14195 https://github.com/D-Programming-Language/dmd/pull/4419
Feb 17 2015
parent Walter Bright <newshound2 digitalmars.com> writes:
On 2/17/2015 11:25 AM, Benjamin Thaut wrote:
 Am 17.02.2015 um 09:13 schrieb Walter Bright:
 Please file bugzilla!
https://issues.dlang.org/show_bug.cgi?id=14195 https://github.com/D-Programming-Language/dmd/pull/4419
Thank you
Feb 17 2015