Bug 1006 – no ambiguity error given if getting function address
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2007-02-24T11:20:00Z
Last change time
2014-02-16T15:26:06Z
Assigned to
bugzilla
Creator
benoit
Comments
Comment #0 by benoit — 2007-02-24T11:20:49Z
this compiles without error.
class C {
void fnc(){
}
void fnc( int a ){
}
static this(){
void* ptr = & fnc; //(1)
}
}
I think (1) should be rejected, because of ambiguity.
Comment #1 by kirklin.mcdonald — 2007-02-24T14:00:46Z
[email protected] wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=1006
>
> Summary: no ambiguity error given if getting function address
> Product: D
> Version: 1.007
> Platform: PC
> OS/Version: Linux
> Status: NEW
> Severity: normal
> Priority: P2
> Component: DMD
> AssignedTo: [email protected]
> ReportedBy: [email protected]
>
>
> this compiles without error.
> class C {
> void fnc(){
> }
> void fnc( int a ){
> }
> static this(){
> void* ptr = & fnc; //(1)
> }
> }
> I think (1) should be rejected, because of ambiguity.
>
>
This should not be made an error without adding a mechanism to get all
of the overloads of a function, for example:
C.fnc.tupleof => Tuple!(void function(), void function(int))
Comment #2 by wbaxter — 2007-02-24T15:31:20Z
It's also very common to use overloads for properties.
void prop(int p) { return mProp=p; }
int prop() { return mProp; }
This is a problem for callback/sigslot mechanisms that very often want to call property-like functions.
caller ~= (int x){ obj.prop=x; }
vs
caller ~= &obj.prop;
The former introduces an extra layer of indirection, is slightly wordy, and is potentially problematic if 'obj' happens to go out of scope. The latter is currently ambiguous.
Apparently a cast can be used currently:
caller ~= cast(void function(int))&obj.prop;
but it is just too ugly. And it's also semantically incorrect and unsafe. I'm not casting I'm trying to disambiguate. And it's unsafe because the cast will succeed even if obj.prop is a float* or anything else.
This is apparently an old proposal (according to Chris N-S) to disambiguate without requiring a cast:
caller ~= &obj.prop(int);
That would be great if that could be done without making the grammar ambiguous.
For generic programming purposes, this should also work:
alias Tuple!(int) ArgTup;
caller ~= &obj.prop(ArgTup);
Comment #3 by wbaxter — 2007-02-24T15:34:18Z
I should add that the problem I spoke of exists only when 'caller.opCatAssign' is a template that accepts multiple function/delegate signatures.
If its opCatAssign takes a particular signature then there's no problem.
Comment #4 by smjg — 2007-02-25T10:32:18Z
*** This bug has been marked as a duplicate of 52 ***