The sample code runs differently in 32 bit (g++ 3.2-7) and 64 bit (g++ 3.2.3-49)
versions of the compiler.  I'm not sure which behavior is correct, but both
version of the compiler yield information on the vector <int> A entity via calls
to A.size() and A.capacity() calls.  I would have expected a bomb at that point.
 The 32 bit compiler treats the call to the destructor at the close of the main
program gracefully and exits normally. The 64 bit version aborts on a segment
violation, creating a core file.  It appears that any attempt to explicity call
a destructor for a STL entity causes an abort on the 64 bit systems when the
compiler-generated call to the destructor is called at the end of scope.  This
behavior is different on the 32 bit compiler version.  

Which is correct behavior?

Sample code follows:
#include <cstddef>
#include <iostream>
#include <vector>

using namespace std;

int main()
{

    int i = 1;
    vector < int > A;

    cout << "Created vector entity " << endl;
    cout << "     Entity size " << A.size() << endl;
    cout << "     Entity capacity " << A.capacity() << endl;
    A.assign( 1000, 1);
    cout << "After assign call " << endl;
    cout << "     Entity size " << A.size() << endl;
    cout << "     Entity capacity " << A.capacity() << endl;
    A.clear();
    cout << "After clear call " << endl;
    cout << "     Entity size " << A.size() << endl;
    cout << "     Entity capacity " << A.capacity() << endl;
    A.reserve( 1 );
    cout << "After reserve zero call " << endl;
    cout << "     Entity size " << A.size() << endl;
    cout << "     Entity capacity " << A.capacity() << endl;
    A.resize( 1 , i);
    cout << "After resize call " << endl;
    cout << "     Entity size " << A.size() << endl;
    cout << "     Entity capacity " << A.capacity() << endl;
    A.~vector();
    cout << "After destructor call " << endl;
    cout << "     Entity size " << A.size() << endl;
    cout << "     Entity capacity " << A.capacity() << endl;
   
}


Output from 32 bit OS, Linux 2.4.18-14smp, Red Hat Linux 8.0, gcc 3.2-7:
Created vector entity 
     Entity size 0
     Entity capacity 0
After assign call 
     Entity size 1000
     Entity capacity 1000
After clear call 
     Entity size 0
     Entity capacity 1000
After reserve zero call 
     Entity size 0
     Entity capacity 1000
After resize call 
     Entity size 1
     Entity capacity 1000
After destructor call 
     Entity size 1
     Entity capacity 1000

application terminates normally

Output from 64 bit g++ on Linux 2.4.21-27.0.1 Red Hat Linux 3.2.3, g++ version
3.2.3:
Created vector entity 
     Entity size 0
     Entity capacity 0
After assign call 
     Entity size 1000
     Entity capacity 1000
After clear call 
     Entity size 0
     Entity capacity 1000
After reserve zero call 
     Entity size 0
     Entity capacity 1000
After resize call 
     Entity size 1
     Entity capacity 1000
After destructor call 
     Entity size 1
     Entity capacity 1000
Segmentation fault (core dumped)

-- 
           Summary: Segmentation violation for repeated calls of destrictor
                    for STL container
           Product: gcc
           Version: 3.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: john dot e dot bussoletti at boeing dot com
                CC: gcc-bugs at gcc dot gnu dot org


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

Reply via email to