When an array of derived objects is deleted through its base class, the 
resulting program seg faults. Could this be caused by destructor iteration with 
invalid <this> pointers?

Reproduced on gcc (GCC) 3.3.3 (cygwin special), egcs-2.91.66 (red hat 6.2), g++ 
(GCC) 3.3 20030304 (Apple Computer, Inc. build 1495), etc

Keylines in the reproducible case below:
Component* c = new Component1[2];
delete [] c;

Reproducible case:
extern "C" int printf(const char *, ...);

class Component{
public:
        Component();
        virtual ~Component();
};
Component::Component() { /*printf("Component::Component 0x%x\n",this);*/}
Component::~Component() { /*printf("Component::~Component 0x%x\n",this); */}

class Component1 : public Component {
private:
        char bytes1[12];
public:
        Component1();
        virtual ~Component1();
};
Component1::Component1() { /*printf("Component1::Component1 0x%x\n",this);*/}
Component1::~Component1() { /*printf("Component1::~Component1 0x%x\n",this);*/ }

int main() 
{
        Component* c = new Component1[2];
        delete [] c;
        
        return 0;
}

-- 
           Summary: Array delete'd through base class causes access
                    violation in prog
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jorik dot dewit at gmail dot com
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i686-pc-cygwin i686-pc-linux ppc-mac-osx


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23132

Reply via email to