Boost logo

Boost :

Subject: Re: [boost] [gil] gcc fail with simple code
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2018-03-28 17:52:02


On 03/28/18 20:30, Christian Henning via Boost wrote:
> Hi all,
>
> we are, at the boost::gil corner, investigating a runtime failure when
> compiling with gcc 5.4. When running in release configuration the following
> code fails:
>
> #include <iostream>
> #include <boost/gil/gil_all.hpp>
>
> using namespace boost::gil;
> using namespace std;
>
> void error_if(bool condition) {
> if (condition)
> throw std::exception();
> }
>
> bits32s c32s_min = channel_traits<bits32s>::min_value();
> bits32s c32s_max = channel_traits<bits32s>::max_value();
>
> // For channel values simply initialize the value directly
> template <typename ChannelValue>
> struct value_core {
> typedef ChannelValue channel_t;
> channel_t _min_v, _max_v;
>
> value_core() : _min_v(channel_traits<ChannelValue>::min_value()),
> _max_v(channel_traits<ChannelValue>::max_value())
> {}
> };
>
> int main(int argc, char *argv[])
> {
> value_core<bits32s> a;
>
> bits32s v_min, v_max;
>
> v_min = channel_convert<bits32s>(c32s_min);
> v_max = channel_convert<bits32s>(c32s_max);
>
> //std::cout << v_min << std::endl;
> // std::cout << this->_min_v << std::endl;
> //std::cout << v_max << std::endl;
> // std::cout << this->_max_v << std::endl;
>
> error_if(v_min != a._min_v || v_max != a._max_v);
> }
>
> The interesting thing is that everything works with the cout's enabled.
>
> Has anyone ever dealt with a similar issue?

Most likely, you have a signed integer overflow somewhere. The code
crashes on gcc 7.2 with -O3 but doesn't crash with -O0 or with -O3 -fwrapv.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk