This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/34839] New: stl vector.resize() strange behaviour
- From: "facorread at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 17 Jan 2008 22:47:47 -0000
- Subject: [Bug c++/34839] New: stl vector.resize() strange behaviour
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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