www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17050] New: Inconsistent overload resolution depending on

https://issues.dlang.org/show_bug.cgi?id=17050

          Issue ID: 17050
           Summary: Inconsistent overload resolution depending on member
                    values of Rvalue struct objects
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: acehreli yahoo.com

Because no member nor struct type is different below, all calls are expected to
be resolved to the same foo overload. However, that's not the case:

struct S {
    const(int)[] c;
}

int foo(S s) {
    return 1;
}

int foo(immutable(S) s) {
    return 2;
}

void main() {

    // This call is resolved to foo(S):
    const(int)[] arr;
    assert(foo(const(S)(arr)) == 1);

    // These are unexpectedly resolved to foo(immutable(S)):
    assert(foo(const(S)()) == 1);        // FAILS
    assert(foo(const(S)(null)) == 1);    // FAILS
}

Ali

--
Dec 31 2016