www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 956] New: Testing Class Object for null reference causes Access Violation Error

reply d-bugmail puremagic.com writes:
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
        }
}


-- 
Feb 13 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=956






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) ...


-- 
Feb 13 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=956


torhu yahoo.com changed:

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




-- 
Feb 13 2007