Opened 8 years ago
Last modified 5 years ago
#11067 assigned Feature Requests
boost::gregorian::date_iterator missing postfix operators ++ and --
| Reported by: | Owned by: | James E. King, III | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | date_time |
| Version: | Boost 1.57.0 | Severity: | Problem |
| Keywords: | boost::gregorian::date, boost::gregorian::date_iterator | Cc: |
Description
/* Consider the following (somewhat canonical) code snippet */ {
std::vector<boost::gregorian::date> dates(count); auto dt_i = dates.begin(); boost::gregorian::month_iterator m_i(some_start_date, 1);
while (dt_i != dts.end())
*dt_i++ = *m_i++; /* this will call prefix ++ operator on m_i
leading to subtle bug */
}
Change History (2)
comment:1 by , 5 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:2 by , 5 years ago
postfix operator implementation requires return-by-value, and in this case the get_offset and get_neg_offset methods are pure virtual, making that impossible in the current implementation.
Note:
See TracTickets
for help on using tickets.

Test (unsure if return is correct; will move into unit test before submitting PR):
#include <boost/date_time/gregorian/gregorian.hpp> int main() { boost::gregorian::date some_date(2007, 8, 9); boost::gregorian::month_iterator m_i(some_date, 1); boost::gregorian::greg_month m(1); m = *m_i++; return !(m == 8); }When building with gcc-7.2 and -Wall:
gcc.compile.c++ ../../../bin.v2/libs/date_time/test/testdate_iterator.test/gcc-gnu-7/debug/threadapi-pthread/gregorian/testdate_iterator.o gregorian/testdate_iterator.cpp: In function ‘int main()’: gregorian/testdate_iterator.cpp:63:20: error: no ‘operator++(int)’ declared for postfix ‘++’ [-fpermissive] date chk = *m_i++; ~~~^~ gregorian/testdate_iterator.cpp:67:15: error: no ‘operator--(int)’ declared for postfix ‘--’ [-fpermissive] chk = *m_i--; ~~~^~ "g++" -O0 -fno-inline -Wall -g -fPIC -m64 -Wunused-local-typedefs -DBOOST_ALL_NO_LIB -DBOOST_ALL_NO_LIB=1 -DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG -DBOOST_DATE_TIME_STATIC_LINK -DDATE_TIME_INLINE -I"../../.." -c -o "../../../bin.v2/libs/date_time/test/testdate_iterator.test/gcc-gnu-7/debug/threadapi-pthread/gregorian/testdate_iterator.o" "gregorian/testdate_iterator.cpp"