I am sorry for not being able to investigate further about this bug.
Please compile and run the following program:
using namespace std;
#include <vector>
#include <iostream>
class MyClass {
public:
MyClass () { cout << "Object created." << endl; };
~MyClass() { cout << "Object destroyed." << endl; };
};
int main (void) {
vector<MyClass> vec;
cout << "Starting..." << endl; vec.resize(3);
cout << "Resizing..." << endl; vec.resize(2);
cout << "Exiting and destroying objects..." << endl;
return 0;
}
The output SHOULD be as follows:
Starting...
Object created.
Object created.
Object created.
Resizing...
Object destroyed.
Exiting and destroying objects...
Object destroyed.
Object destroyed.
The produced output is as follows:
Starting...
Object created.
Object destroyed.
Resizing...
Object created.
Object destroyed.
Object destroyed.
Exiting and destroying objects...
Object destroyed.
Object destroyed.
A similar behaviour is observed when declaring vec with the line
vector<MyClass> vec(1, MyClass());
I reproduced the behavior in a i686-pc-linux-gnu box.
--
Summary: stl vector.resize() strange behaviour
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: facorread at gmail dot com
GCC host triplet: x86_64-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34839