Re: [Boost-bugs] [Boost C++ Libraries] #3606: One potential bug, and lots of warnings in DateTime

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #3606: One potential bug, and lots of warnings in DateTime
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-07-01 17:45:43


#3606: One potential bug, and lots of warnings in DateTime
---------------------------+------------------------------------------------
  Reporter: johnmaddock | Owner: az_sw_dude
      Type: Bugs | Status: assigned
 Milestone: Boost 1.42.0 | Component: date_time
   Version: | Severity: Problem
Resolution: | Keywords:
---------------------------+------------------------------------------------
Changes (by az_sw_dude):

  * status: new => assigned
  * version: Boost 1.40.0 =>

Comment:

 The initial issue here:

 int i = 0xf0001;
 boost::gregorian::greg_day d(i)

 I'm afraid that this is an issue with C++ itself -- it will automatically
 convert integer types that it really shouldn't. In this case greg_day
 takes and unsigned short simply truncating the value -- so in fact the
 value turns out to be within the valid range. In fact if 0xf0000 had been
 supplied an exception would have been thrown. So, at some level there is
 an argument that sorry folks, this is C++ if you deal with integer types
 you're going to have to know what you're doing.

 As an example:


 {{{
  //integer_behavior.cpp
  // g++-4.6 -Wall -Wextra -pedantic integer_behavior.cpp

  //no warnings, no errors...

  #include <iostream>

  int main()
  {
   unsigned short i = 0;
   int j = 0xf0001;
   i = j;
   std::cout << i << std::endl; //0
   return 0;
  }
 }}}




 Still, I take the point that there are possibly a few places where this
 could be cleaned up -- the template constructor suggestion isn't a bad one
 since VC6 doesn't need to be supported any longer. So I'll accept the
 defect for now and see how to eventually deal with it -- in the grand
 scheme of things it's likely a low priority.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/3606#comment:2>
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:09 UTC