[Issue 1227] New: Access Violation when using comparison of template	class pointer
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Fri May 11 07:45:06 PDT 2007
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=1227
           Summary: Access Violation when using comparison of template class
                    pointer
           Product: D
           Version: 1.014
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: aurelien.vermifuge at gmail.com
THe compiler seem to have a problem with template class. I think the code will
be more usefull than a long description with ma chaotic english.
I made that :
---- util/linkedlist.d ----
class LinkedList(TypeList=Object)
{
        private LinkedListLink!(TypeList) first, last;
        private int count;
        public this()
        {
                this.first = null;
                this.last = null;
                this.count = 0;
        }
        public void add(TypeList T)
        {
                LinkedListLink!(TypeList) n;
                synchronized(this)
                {
                        try
                        {
                                n = new LinkedListLink!(TypeList) (last, T);
                        } catch (OutOfMemoryException e)
                        {
                                throw e;
                        }
                        if ( this.last==null )
                        {
                                this.first = n;
                                this.last = n;
                        } else
                        {
                                this.last.next = n;
                                this.last = n;
                        }
                        count++;
                }
        }
}
class LinkedListLink(TypeList=Object)
{
        public TypeList value;
        public LinkedListLink next, previous;
        public this(TypeList T)
        {
                value = T;
                next = null;
                previous = null;
        }
        public this(LinkedListLink prev, TypeList T)
        {
                value = T;
                next = null;
                previous = prev;
        }
}
---- main.d ----
int main(char[][] args)
{
        LinkedList!(int) listEntiers;
        try
        {
                listEntiers = new LinkedList!(int)();
        } catch (OutOfMemoryException e)
        {
                printf("No more memory u_u");
        }
        for (int i=0; i<15; i++)
        {
                try
                {
                        listEntiers.add(i);
                } catch (OutOfMemoryException e)
                {
                        printf("BUG");
                }
        }
}
-------------------------------
It compile well, but when the add is called, the programm make an "Access
Violation" and stop running. I have looked at the ASM generated code, and I saw
that :
( eax = pointer to object )
mov eax, [eax+0Ch] // Put the this.last value into eax, the value is null
mov eax, [eax]     // Try to read into the object à the offset 0 --> Exception
If I put : this.last = null; it works well, dans the generated code is :
( eax = pointer to object )
mov [eax+0Ch], 0   // Correct
but the condition is not well formed.
Hope it will be usefull.
-- 
    
    
More information about the Digitalmars-d-bugs
mailing list