This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: libstdc++/8359: STL container can fault at runtime destroying contained objects with virtual destructors
- From: bkoz at gcc dot gnu dot org
- To: gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org, vwhite at entercept dot com
- Date: 31 Oct 2002 17:21:10 -0000
- Subject: Re: libstdc++/8359: STL container can fault at runtime destroying contained objects with virtual destructors
- Reply-to: bkoz at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org, vwhite at entercept dot com, gcc-gnats at gcc dot gnu dot org
Synopsis: STL container can fault at runtime destroying contained objects with virtual destructors
State-Changed-From-To: feedback->open
State-Changed-By: bkoz
State-Changed-When: Thu Oct 31 09:21:09 2002
State-Changed-Why:
Just adding this bit.
Without a test case, this bug report is so sufficiently vague as to be eligible for suspension.
As an aid to you, I've provided a sample test case. It doesn't core. However, without the required copy constructor (vector requires all contained types to be both copyconstrible and assignable) you'll get a core. Perhaps this is what you are seeing?
-benjamin
#include <new>
#include <vector>
struct base
{
protected:
int i;
char* p;
public:
base(int j = 0, const char* name = "hush hush"): i(j)
{
p = new char[strlen(name) + 1];
strcpy(p, name);
}
~base()
{ delete [] p; }
};
struct derived: public base
{
derived(int j2 = 5, const char* name2 = "mush mush"): base(j2, name2) { }
#if 0
// Define to make conformant to vector requirements.
derived(const derived& dup)
{
i = dup.i;
delete [] p;
p = new char[strlen(dup.p) + 1];
strcpy(p, dup.p);
}
derived&
operator=(const derived& dup)
{
i = dup.i;
delete [] p;
p = new char[strlen(dup.p) + 1];
strcpy(p, dup.p);
return *this;
}
#endif
};
int main()
{
// Must be copyconstructible and assignable.
std::vector<derived> vec(6);
vec.push_back(derived(3, "blow up"));
return 0;
}
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8359