Thread overview
[Issue 956] New: Testing Class Object for null reference causes Access Violation Error
Feb 13, 2007
d-bugmail
Feb 13, 2007
d-bugmail
Feb 13, 2007
d-bugmail
February 13, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=956

           Summary: Testing Class Object for null reference causes Access
                    Violation Error
           Product: D
           Version: 1.005
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: hennrich.bloebaum@gmx.de


class MyClass
{

}

void main()
{
        MyClass[] myArray = null;
        MyClass myObject = null;

        if(!myArray) { // Ok
        }

        if(myArray == null) { // Works on dynamic arrays
        }

        if(!myObject) { // Ok
        }

        if(myObject == null) { // Error: Access Violation
        }
}


-- 

February 13, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=956





------- Comment #1 from ddparnell@bigpond.com  2007-02-13 08:20 -------
Not a bug.

The form "object == null" gets transformed as object.opEquals(null), and so if the object is actually null already, the invocation of it's opEquals member fails.

The documented method of testing for null objects is

   if (object is null) ...


-- 

February 13, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=956


torhu@yahoo.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




--