[Bug target/69789] g++ -O2 is removing tests against a variable that can be changed
tmark at isc dot org
gcc-bugzilla@gcc.gnu.org
Tue Feb 23 11:45:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69789
--- Comment #3 from Thomas Markwalder <tmark at isc dot org> ---
After further analysis we've discovered that the optimizer does not remove the
tests, it alters the comparison of (ec == enumerated value). If one replaces
the "ec" with "ec.value()" in the expressions, such that you are explicitly
comparing the interger error value the code works correctly when optimized:
{{{
:
// Retry operation if interrupted by signal.
if (ec.value() == boost::asio::error::interrupted)
continue;
// Check if we need to run the operation again.
if (ec.value() == boost::asio::error::would_block
|| ec == boost::asio::error::try_again)
return false;
:
}}}
Alternatively, adding an inline operator:
{{{
inline friend bool operator==( const error_code & lhs,
const int & rhs ) BOOST_SYSTEM_NOEXCEPT
{
return lhs.m_val == rhs;
}
}}}
to error_code class also avoids the issue.
More information about the Gcc-bugs
mailing list