This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Dear developers,
I think there's something wrong with the optimization step of g++:
The C++-program
#include <iostream>
#include <vector>
#include <algorithm>
struct Data
{
int x[2], y;
Data ( int i ) { x[0]=i; x[1]=0; y=0; }
};
bool operator == ( const Data &d1, const Data &d2 )
{
for ( int i=0; i<2; ++i )
if (d1.x[i]!=d2.x[i]) return false;
return d1.y==d2.y;
}
int main()
{
vector<Data> DataList;
DataList.reserve(8);
for ( int j=0; j<2; ++j )
for ( int i=0; i<4; ++i )
{
Data d(i);
if (find(DataList.begin(),DataList.end(),d)==DataList.end())
DataList.push_back(d);
}
cout << "Size of list: " << DataList.size() << "\nElements:";
for ( int i=0; i<DataList.size(); i++ )
cout << " " << DataList[i].x[0];
cout << endl;
return 0;
}
should generate the output
Size of list: 4
Elements: 0 1 2 3
(it indeed does, if compiled without optimization).
However, if compiled using
g++ -O1 bug.cpp
the ouput reads:
Size of list: 8
Elements: 0 1 2 3 0 1 2 3
Some information on my compiler and computer system:
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.97/specs
Configured with:
gcc version 2.97 20001030 (experimental)
SuSE Linux 6.0, running kernel 2.2.12 with SMP enabled
on a Gigabyte dual Pentium II board (233 MHz)
Attached you will find the preprocessed file generated with
g++ -E -O1 -g bug.cpp
I hope that helps finding the bug!
With best regards,
Volker Reichelt
------------------------------------------------------------------------------
Volker Reichelt
Lehrstuhl fuer Numerische Mathematik
(chair for numerical mathematics)
RWTH Aachen
Templergraben 55
D-52056 Aachen
Germany
Tel: (+49) 241/807067, Fax: (+49) 241/8888349
email: reichelt@igpm.rwth-aachen.de
http://www.igpm.rwth-aachen.de/reichelt
------------------------------------------------------------------------------
BZh91AY&SYj) _P`x>v*چP:$ !oWOm*ޝ{ǻuxr{`&Z܃ y{-S\{Pw{xzj7l>ڥjT3TȠI% H$}Oe䛾o^ǹAo{c}=}^GaU5ۚg^] ^} `ml_Z>s9T9`/fԮ.g{Ukӛ%4wj-`#nݗvym{E6oyT]u_}Ϻk{_/[syϭ>QxN7ێ;;ʘk[lRw@
/{̓1륝e ۶u5<