[Issue 9665] New: Structure constant members can not be initialized if have opAssign

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 8 02:49:19 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9665

           Summary: Structure constant members can not be initialized if
                    have opAssign
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: maximzms at gmail.com


--- Comment #0 from Maksim Zholudev <maximzms at gmail.com> 2013-03-08 02:49:18 PST ---
Normally constant members of a structure can be initialized in constructor.
However this is not possible if they have overloading of assignment operator.

This restricts usage of complex numbers from std.complex since they are
structures with opAssign.

-------------------
struct Foo1 // opAssign is a function
{
    int value;
    void opAssign(int src) { value = src; }
}

struct Foo2 // opAssign is a template
{
    int value;
    void opAssign()(int src) { value = src; }
}

struct Boo
{
    const Foo1 f1;
    const Foo2 f2;

    this(int src)
    {
        f1 = src; // Error!
        f2 = src; // Error!
    }
}

void main() {}
-------------------
test.d(20): Error: mutable method test.Foo1.opAssign is not callable using a
const object
test.d(21): Error: template test.Foo2.opAssign does not match any function
template declaration. Candidates are:
test.d(10):        test.Foo2.opAssign()(int src)
test.d(21): Error: template test.Foo2.opAssign()(int src) cannot deduce
template function from argument types !()(int)
-------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list