Bug 23132 - Array delete'd through base class causes access violation in prog
Summary: Array delete'd through base class causes access violation in prog
Status: RESOLVED DUPLICATE of bug 22609
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-29 11:26 UTC by Jorik
Modified: 2005-07-29 12:29 UTC (History)
1 user (show)

See Also:
Host: i686-pc-cygwin i686-pc-linux ppc-mac-osx
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jorik 2005-07-29 11:26:39 UTC
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;
}
Comment 1 Andrew Pinski 2005-07-29 11:47:18 UTC

*** This bug has been marked as a duplicate of 22609 ***
Comment 2 Jorik 2005-07-29 12:29:39 UTC
(In reply to comment #1)
> *** This bug has been marked as a duplicate of 22609 ***

Sorry about reporting a duplicate. I had looked/searched. Maybe the default 
settings for the query form should include issues with status RESOLVED (but 
with resolution <> FIXED; i.e. especially INVALID  (and WONTFIX/DUPLICATE).
Maybe this would avoid some duplicate bug reports?