#5614 closed Bugs (invalid)
date bug in release (boost 1.46)
Reported by: | Owned by: | az_sw_dude | |
---|---|---|---|
Milestone: | To Be Determined | Component: | date_time |
Version: | Boost 1.46.1 | Severity: | Problem |
Keywords: | Cc: |
Description
The bug is present only in Release (WinXP + Boost 1.46) not in Debug.
The bug is produced as follows:
#include "boost/date_time/gregorian/gregorian.hpp" using namespace boost::gregorian; void func() { date todaysdate(day_clock::local_day()); printf("%i-%02i-%02i\n",todaysdate.year(), todaysdate.month(), todaysdate.day()); }
This prints gibberish values or more precisely, the lowest 16 bits are correct but the highest 16 bits contain random data.
The date itself seems to work perfectly well, I can compare dates, increment and so on, it is only the year(), month() etc. functions that seems broken.
HTH & keep up the good work!!
Valmond
Change History (3)
comment:1 by , 11 years ago
Component: | None → date_time |
---|---|
Owner: | set to |
comment:2 by , 9 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:3 by , 9 years ago
Except that neither Qt nor MSVC 2010 detects this.
The solution would have been to always truncate the numbers but, hey, no problem. On the other hand, few people uses Boost any more (it's all in 0x11 now) for new projects and as this ticket have been open for years, older projects will have done workarounds and as I said, it doesn't impact new projects.
Cheers
Your use of printf is incorrect. year(), month() and day() methods return class types which have conversion operators to unsigned short. This results in incorrect arguments being passed to printf, which makes the output incorrect.
A good compiler would warn you about such inconsistency, and gcc 4.8 actually does that: