I have djgpp g++ compiler 4.0.0 running on Windows.
To compile I use
gpp -o file -O2 file.cpp
After executing following code
---------------------
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
using namespace std;
int M;
struct pnt{
char c;
int x;
char dir;
};
vector<pnt> a;
pnt tmp;
int main(){
M = 1000000;
for(int i = 0;i<M;i++){
tmp.c = 'S';
tmp.x = 1;
tmp.dir = 0;
a.push_back(tmp);
tmp.x = 2;
tmp.dir = 1;
a.push_back(tmp);
}
return 0;
}
---------------------
there will be memory bad_alloc exception
------------
terminate called after throwing an instance of 'std::bad_alloc'
what(): St9bad_alloc
Abort!
Exiting due to signal SIGABRT
Raised at eip=0000e64e
eax=000d6d64 ebx=00000120 ecx=00000000 edx=00000000 esi=00000001 edi=00056f58
ebp=000d6e10 esp=000d6d60 program=D:\MYCONT~1\WROC\2\TMP.EXE
cs: sel=08ff base=01cd0000 limit=0194ffff
ds: sel=0907 base=01cd0000 limit=0194ffff
es: sel=0907 base=01cd0000 limit=0194ffff
fs: sel=08d7 base=0000e270 limit=0000ffff
gs: sel=0917 base=00000000 limit=0010ffff
ss: sel=0907 base=01cd0000 limit=0194ffff
App stack: [000d6f58..00056f58] Exceptn stack: [00056eac..00054f6c]
Call frame traceback EIPs:
0x0000e574
0x0000e64e
0x0000b3fb
0x00020e5e
0x0001c0f4
0x0001c12e
0x0001bce3
0x000193dd
0x000214f7
0x000016eb
0x0000abd8
-----------
Of course, while using older gcc (i.e. 3.2.3) code works fine.
There must be the same problem on g++ 4.0.3 at Linux platform.
--
Summary: bad allocation while adding new elements to vector
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: algorithmus at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26825