Opened 6 years ago

Closed 5 years ago

#12363 closed Bugs (fixed)

int_adapter is_signed should be const

Reported by: James E. King, III <jim.king@…> Owned by: James E. King, III
Milestone: Boost 1.67.0 Component: date_time
Version: Boost 1.54.0 Severity: Cosmetic
Keywords: Cc:

Description

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.

Change History (3)

comment:1 by James E. King, III, 5 years ago

Owner: changed from az_sw_dude to James E. King, III
Status: newassigned

comment:2 by James E. King, III, 5 years ago

Milestone: To Be DeterminedBoost 1.67.0

comment:3 by James E. King, III, 5 years ago

Resolution: fixed
Status: assignedclosed

Fix merged to master; resolved.

Note: See TracTickets for help on using tickets.