[Boost-bugs] [Boost C++ Libraries] #11519: Strange value of ptime variable

Subject: [Boost-bugs] [Boost C++ Libraries] #11519: Strange value of ptime variable
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-07-31 11:42:29


#11519: Strange value of ptime variable
------------------------------+------------------------
 Reporter: a0607892@… | Owner: az_sw_dude
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: date_time
  Version: Boost 1.58.0 | Severity: Problem
 Keywords: |
------------------------------+------------------------
 The bug is produced by this example program:


 {{{
 int main() {

     int n = ((20 * 2700 - 4000.0) / 20 / 300.0 + 0.5);
     boost::posix_time::ptime from;
     boost::posix_time::ptime beg =
 boost::posix_time::time_from_string("2015-07-29 11:40:00");
     beg = beg + boost::posix_time::minutes(5);
     beg = beg + boost::posix_time::minutes(5);
     beg = beg + boost::posix_time::minutes(5);
     beg = beg + boost::posix_time::minutes(5);
     beg = beg + boost::posix_time::minutes(5);
     beg = beg + boost::posix_time::minutes(5);
     beg = beg + boost::posix_time::minutes(5);
     beg = beg + boost::posix_time::minutes(5);
     beg = beg + boost::posix_time::minutes(5);
     beg = beg + boost::posix_time::minutes(5);
     beg = beg + boost::posix_time::minutes(5);
     beg = beg + boost::posix_time::minutes(5);
     beg = beg + boost::posix_time::minutes(5) +
                 boost::posix_time::minutes(5) +
 boost::posix_time::minutes(5) + boost::posix_time::minutes(5) +
                 boost::posix_time::minutes(5) +
 boost::posix_time::minutes(5) + boost::posix_time::minutes(5) +
                 boost::posix_time::minutes(5) +
 boost::posix_time::minutes(5) + boost::posix_time::minutes(5) +
                 boost::posix_time::minutes(5) +
 boost::posix_time::minutes(5) + boost::posix_time::minutes(5) +
                 boost::posix_time::minutes(5) +
 boost::posix_time::minutes(5) + boost::posix_time::minutes(5) +
                 boost::posix_time::minutes(5) +
 boost::posix_time::minutes(5) + boost::posix_time::minutes(5) +
                 boost::posix_time::minutes(5) +
 boost::posix_time::minutes(5) + boost::posix_time::minutes(5) +
                 boost::posix_time::minutes(5) +
 boost::posix_time::minutes(5) + boost::posix_time::minutes(5) +
                 boost::posix_time::minutes(5) +
 boost::posix_time::minutes(5) + boost::posix_time::minutes(5) +
                 boost::posix_time::minutes(5) +
 boost::posix_time::minutes(5) + boost::posix_time::minutes(5) +
                 boost::posix_time::minutes(5) +
 boost::posix_time::minutes(5) + boost::posix_time::minutes(5) +
                 boost::posix_time::minutes(5) +
 boost::posix_time::minutes(5);


     for(int i = 7; i < n; i++) {
         from = beg + boost::posix_time::minutes(5 * i);
         if(from!=beg+ boost::posix_time::minutes(5 * i))
             std::cout << "ERROR IN TIME: " <<
 boost::posix_time::to_iso_extended_string(from) << std::endl <<
 boost::posix_time::to_iso_extended_string(beg+
 boost::posix_time::minutes(5 * i)) << std::endl;
     }


   return 0;
 }
 }}}

 The result of this code is that it reaches the output (although it
 shouldn't) and outputs a strange value for ''from''.
 I compiled this sample file with g++ 4.6.3 on Ubuntu 12.04 with the
 compiler flags ''-O3'' and ''-frounding-math''. Although ''-frounding-
 math'' is necessary to produce this bug for this small example, in a much
 larger program the bug is still there without this flag.

 While debugging this code it seems for me that in
 {{{
 from = beg + boost::posix_time::minutes(5 * i);
 }}}
 the minutes are never initialized (but debugging with optimization is
 quite difficult).

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11519>
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:18 UTC