[Issue 2557] inconsistent behavior when taking reference to member without instance

2017-12-04 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=2557

Mike Franklin  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |WONTFIX

--


[Issue 2557] inconsistent behavior when taking reference to member without instance

2017-12-04 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=2557

--- Comment #11 from Mike Franklin  ---
I tested the test case with DMD 2.077.1 and it correctly rejects taking a
reference to a non-static member function through the type

Also, the "Version" for this PR is listed as "D1 (Retired)".  It is my
understanding that D1 is no longer supported, so closing this issue.

--


[Issue 2557] inconsistent behavior when taking reference to member without instance

2017-12-04 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=2557

Mike Franklin  changed:

   What|Removed |Added

 CC||slavo5...@yahoo.com

--- Comment #10 from Mike Franklin  ---
For convenience, I'm adding the source code from the original post's attachment
here:

module method_ref;

class A {
void fun() {}
}

void main() {
/* This works correctly and can sometimes be very useful */
A a = new A;
void function() fn1 = &A.fun;
void delegate() dg1;
dg1.ptr = cast(void*)a;
dg1.funcptr = fn1;
dg1();
}

class B {
/+ static /* works if static */ +/ void dofun() {
/* Error: this for fun needs to be type A not type method_ref.B */
A a = new A;
void function() fn2 = &A.fun;
void delegate() dg2;
dg2.ptr = cast(void*)a;
dg2.funcptr = fn2;
dg2();
}
}

It can be tested online here: https://run.dlang.io/is/9GAvd4

--


[Issue 2557] inconsistent behavior when taking reference to member without instance

2017-12-04 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=2557

Mike Franklin  changed:

   What|Removed |Added

   See Also||https://issues.dlang.org/sh
   ||ow_bug.cgi?id=3720

--


[Issue 2557] inconsistent behavior when taking reference to member without instance

2009-01-14 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2557





--- Comment #9 from d...@brian.codekitchen.net  2009-01-14 16:46 ---
> It doesn't work.  "works" means "behaves correctly", not "compiles without 
> error".

I understand the difference between "works" and "compiles', it does work in my
testing. The method body I'm taking a pointer to is empty in the test case but
I first ran into this inconsistency while refactoring some code, where the
method body was *not* empty and the code inside the method executed correctly.
Whether it *should* work or not is certainly debatable, but I find it a useful
behavior except for the inconsistency shown.


-- 



[Issue 2557] inconsistent behavior when taking reference to member without instance

2009-01-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2557





--- Comment #8 from s...@iname.com  2009-01-12 07:15 ---
(In reply to comment #7)
> Makes sense. Perhaps, another enhancement report should be created with a
> request to change typeof(&A.foo) from void function() to void delegate() with 
> a
> dg.ptr being null.

That would still be prone to accidental misuse IMO.

Really, D should do one of the following:
(a) add method pointer types
(b) define &A.foo to be of a type that has the context pointer as just another
parameter (which might break if ABI changes to support function-to-delegate
conversion are implemented)
(c) (continue to) disallow &A.foo altogether


-- 



[Issue 2557] inconsistent behavior when taking reference to member without instance

2009-01-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2557





--- Comment #7 from 2kor...@gmail.com  2009-01-12 04:53 ---
Makes sense. Perhaps, another enhancement report should be created with a
request to change typeof(&A.foo) from void function() to void delegate() with a
dg.ptr being null.


-- 



[Issue 2557] inconsistent behavior when taking reference to member without instance

2009-01-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2557





--- Comment #6 from s...@iname.com  2009-01-12 03:09 ---
(In reply to comment #5)
> That's a feature! Even if method is not static, it still has a single unique
> body. If so, why can't you take its address?

http://www.digitalmars.com/d/1.0/type.html#delegates
"There are no pointers-to-members in D, but a more useful concept called
delegates are supported."

Even if there were, the type would not be
void function()
as is declared in the attached code, but rather
void function(A)
or perhaps something like
void A.function()
akin to C++ notation (IIRC)
void (A::*)()

Maybe
void function()
would work if the calling convention specifies that the context pointer be
always passed in a register that is never used for any other kind of function
argument, but that isn't the case in the current ABI.


-- 



[Issue 2557] inconsistent behavior when taking reference to member without instance

2009-01-11 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2557





--- Comment #5 from 2kor...@gmail.com  2009-01-12 00:26 ---
That's a feature! Even if method is not static, it still has a single unique
body. If so, why can't you take its address?


-- 



[Issue 2557] inconsistent behavior when taking reference to member without instance

2009-01-11 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2557





--- Comment #4 from s...@iname.com  2009-01-11 19:09 ---
But your code tries to use &A.fun, not &a.fun.  For &A.fun to make any sense
with A being a type, fun would have to be a static method of A.


-- 



[Issue 2557] inconsistent behavior when taking reference to member without instance

2009-01-11 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2557





--- Comment #3 from 2kor...@gmail.com  2009-01-11 17:42 ---
(In reply to comment #2)
> The code is wrong regardless of whether dofun is static or not.  A.fun needs 
> an
> object of type A.  But it doesn't have one.
> 

I'm not so sure. Object of type A is provided by these two lines of code:
A a = new A;
dg2.ptr = cast(void*)a;


-- 



[Issue 2557] inconsistent behavior when taking reference to member without instance

2009-01-11 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2557


s...@iname.com changed:

   What|Removed |Added

 CC||s...@iname.com
   Keywords||accepts-invalid




--- Comment #2 from s...@iname.com  2009-01-11 17:28 ---
It doesn't work.  "works" means "behaves correctly", not "compiles without
error".

The code is wrong regardless of whether dofun is static or not.  A.fun needs an
object of type A.  But it doesn't have one.

--
bz2557.d(21): Error: this for fun needs to be type A not type method_ref.B
bz2557.d(21): Error: cannot implicitly convert expression (&this.fun) of type
void delegate() to void function()
--


-- 



[Issue 2557] inconsistent behavior when taking reference to member without instance

2009-01-05 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2557





--- Comment #1 from d...@brian.codekitchen.net  2009-01-05 09:50 ---
Created an attachment (id=285)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=285&action=view)
test case


--