www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12945] New: Deprecation for legacy static opCall feature in

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

          Issue ID: 12945
           Summary: Deprecation for legacy static opCall feature in
                    initializing
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: k.hara.pg gmail.com

It is an old feature to emulate constructor call from D1 age.

struct S {
    int num;
    static S opCall(int n) {
        S s;
        s.num = n;
        return s;
    }
}
void main() {
    S s = 1;
    // This line is translated to:
    // S s = S.opCall(1);
}

But in D2, "implicit constructor call" feature properly supports such the
initializing syntax.

struct S {
    int num;
    this(int n) {
        this.num = n;
    }
}
void main() {
    S s = 1;
    // This line is translated to:
    // S s = S(1);
}

Therefore, we can deprecate/remove the problematic opCall feature in
initializing.

--
Jun 18 2014