Boost logo

Boost Users :

Subject: [Boost-users] Boost Iterator Adaptor, with a mutable member variable is optimized out incorrectly
From: Jonas Hörsch (jonas_at_[hidden])
Date: 2013-10-23 04:25:43


hello everyone,

i am not sure if this is actually a question about boost usage. but in
the attached code i'm stuck with the unlikely situation, that gcc
optimizes away my code and produces garbage for -On (n>=1), while it
works like intended with -O0.

attached is the minimal code, with which i could reproduce the problem:


on linux i686 g++ version 4.6.3 and x86_64 g++ version 4.7.2, using
packaged boost_1_54_0 in both instances, i see the following: when i
compile the code with optimization (-O1)

% ./iterator_adaptor_weirdness
-1219536795 -1219536795

and without (-O0)

% ./iterator_adaptor_weirdness
4 2

is this a bug in gcc? is it wrong to use mutable variables in
conjunction with iterator_adaptor?

any insight is appreciated,

jonas

P.S.: I know, that this particular instance of the problem, might be
better solved using a transform_iterator, but unfortunately that
approach doesn't scale.





Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net