map and -O2

Eric Bourque ericb@computer.org
Sat Apr 13 23:15:00 GMT 2002


Is there a known problem with using optimization and map? I am
consistently getting segfaults with code compiled with -O2 (gcc
3.0.4-linux-i686) for the following:

map<foo,bar> keys;

...

map<foo,bar>::iterator i=keys.begin();
cout << (*i).first << endl; // as soon as I dereference i the problem
occurs

oddly keys.size() returns the correct (positive) number of elements, so
I don't see how the iterators could be screwed up. All this stuff gets
inlined so it's real hard to debug.

Without -O2, the code works fine.

Any ideas or suggestions?

Cheers,

Eric

-- 
Eric Bourque
Ph.D. Candidate, Centre for Intelligent Machines, McGill University.

PGP Fingerprint : B57E FA15 E100 4C20 538F  56F0 78B9 582D 75C0 CFE0



More information about the Libstdc++ mailing list