libstdc++/8359: STL container can fault at runtime destroying contained objects with virtual destructors

bkoz@gcc.gnu.org bkoz@gcc.gnu.org
Thu Oct 31 09:24:00 GMT 2002


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



More information about the Gcc-bugs mailing list