[Bug 52] New: ambiguous function pointer silently excepted

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 14 13:43:32 PST 2006


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 at digitalmars.com
        ReportedBy: shro8822 at 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; }


-- 




More information about the Digitalmars-d-bugs mailing list