[Boost-bugs] [Boost C++ Libraries] #12363: int_adapter is_signed should be const

Subject: [Boost-bugs] [Boost C++ Libraries] #12363: int_adapter is_signed should be const
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-07-29 13:28:52


#12363: int_adapter is_signed should be const
---------------------------------------------+------------------------
 Reporter: James E. King, III <jim.king@…> | Owner: az_sw_dude
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: date_time
  Version: Boost 1.54.0 | Severity: Cosmetic
 Keywords: |
---------------------------------------------+------------------------
 In int_adapter at lines 171 to 183, with coverity comments:

 {{{
 171 bool operator<(const int& rhs) const
 172 {
 173 // quiets compiler warnings
    assignment: Assigning: is_signed = true.
 174 bool is_signed = std::numeric_limits<int_type>::is_signed;
    const: At condition is_signed, the value of is_signed must be equal to
 1.
    dead_error_condition: The condition !is_signed cannot be true.
 175 if(!is_signed)
 176 {
    CID 10153 (#1 of 1): 'Constant' variable guards dead code
 (DEADCODE)dead_error_line: Execution cannot reach this statement: if
 (boost::date_time::int_a....
    Local variable is_signed is assigned only once, to a constant value,
 making it effectively constant throughout its scope. If this is not the
 intent, examine the logic to see if there is a missing assignment that
 would make is_signed not remain constant. Otherwise, declaring is_signed
 as const will suppress this defect.
 177 if(is_neg_inf(value_) && rhs == 0)
 178 {
 179 return true;
 180 }
 181 }
 182 return (compare(rhs) == -1);
 183 }
 }}}

 Coverity picks this up indicating that if is_signed was const (or perhaps
 even better in C++11 a constexpr?) it would allow the compiler to optimize
 better.

 This is in the development trunk back to at least 1.54.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12363>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC