Opened 7 years ago

Closed 5 years ago

#11519 closed Bugs (invalid)

Strange value of ptime variable

Reported by: a0607892@… Owned by: James E. King, III
Milestone: To Be Determined Component: date_time
Version: Boost 1.58.0 Severity: Problem
Keywords: Cc:

Description

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).

Change History (3)

comment:1 by a0607892@…, 7 years ago

With a newer version of g++ (4.7 as well as 5.1) and also with icpc (version 15) the bug cannot be reproduced. The program is then also Valgrind clean. Therefore, in my opinion, it seems to be a bug in the compiler.

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

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

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

Resolution: invalid
Status: newclosed

Given this is a compiler bug in an old compiler, I am resolving it as invalid.

Note: See TracTickets for help on using tickets.