Boost Iterator Adaptor, with a mutable member variable is optimized out incorrectly
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.
Your code invokes undefined behaviour.
boost::copy() will call code like this in a loop:
*out = *in;
where 'out' is your ostream iterator and 'in' is a
reverse_iterator
participants (2)
-
Jonas Hörsch
-
Nathan Ridge