www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Bug 52] New: ambiguous function pointer silently excepted

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=52

           Summary: ambiguous function pointer silently excepted
           Product: D
           Version: 0.149
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: shro8822 uidaho.edu


The use of auto with an assignment from an overloaded function results in an
ambiguous type. The type of the variable is depends on the order that the
overloads are defined. switch the order and the type changes (see code below).
BTW this bug also exists in DMC.

------------------------
void main()
{
    S s;
    int delegate(int) dlp_i = &s.fn;
    int delegate()    dlp_v = &s.fn;
    auto dlp_x = &s.fn;

    dlp_i(1);  // works
    dlp_v();   // works

    dlp_x();   // what type is dlp_x ??
    dlp_x(1);  // it depends in the order of fn's in S


    // same problem with fn ptrs


    int function(int) fnp_i = &fn;
    int function()    fnp_v = &fn;
    auto fnp_x = &fn;

    fnp_i(1);  // works
    fnp_v();   // works

    fnp_x();   // what type is fnp_x ??
    fnp_x(1);  // it depends in the order of fn's in S

}

struct S
{
    int j;

    // swap these to change the type of dlp_x
    int fn(int i) { j = i; return j; }
    int fn()      { j = 0; return j; }
}


// swap these to change the type of fnp_x
int fn(int i) { return i; }
int fn()      { return 0; }


-- 
Mar 14 2006
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=52


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
            Summary|ambiguous function pointer  |ambiguous function pointer
                   |silently excepted           |silently accepted





AFAIK this also occurs with typeof, and probably functions overloaded to take
function pointers as well.  While the spec doesn't comment in the ambiguity,
it's incompatible with something that the spec does say somewhere or other:
that the semantics of a program should never be altered by the order of
declarations.


-- 
May 18 2006