www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15847] New: It is not an error to call opAssign on an

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

          Issue ID: 15847
           Summary: It is not an error to call opAssign on an
                    uninitialized object
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: monkeyworks12 hotmail.com

struct Test
{
    int n;

    int opAssign(int val)
    {
        assert(n == int.init, "n is in an uninitialized state");
        return n = val;
    }
}

void main()
{
    Test t = void;
    //opAssign should not be called here as t is uninitialized
    t = 0; //BOOM
}

--
Mar 29 2016