Boost logo

Boost :

From: Richard Hadsell (hadsell_at_[hidden])
Date: 2007-05-02 10:15:51


Using g++ 3.4.4 (on 64-bit Linux) my source won't compile
gregorian_calendar_base<>::is_leap_year. The problem stems from the '%'
operator with mixed types. My code includes (unfortunately) a class
that has arithmetic operators with most of the integer and
floating-point types on the left, constructors from those types, and
conversion operators to those types. The compiler finds the ambiguity
and can't decide between the built-in operator%(int, int) and all the
other possibilities with my nasty class's '%' operators.

I fixed the problem in gregorian_calendar.ipp by casting 'year' to 'int'
in 'is_leap_year'. This is the diff:

diff -u -r1.1.1.1 gregorian_calendar.ipp
--- boost/date_time/gregorian_calendar.ipp 27 Apr 2007 17:10:19 -0000 1.1.1.1
+++ boost/date_time/gregorian_calendar.ipp 2 May 2007 13:59:31 -0000
@@ -164,7 +164,7 @@
   gregorian_calendar_base<ymd_type_,date_int_type_>::is_leap_year(year_type year)
   {
     //divisible by 4, not if divisible by 100, but true if divisible by 400
- return (!(year % 4)) && ((year % 100) || (!(year % 400)));
+ return (!(static_cast<int>(year) % 4)) && ((static_cast<int>(year) % 100) || (!(static_cast<int>(year) % 400)));
   }
   
   //! Calculate the last day of the month

We have had this problem since starting to use the date_time library in
1.32.0. The user was not interested in reporting it, and I hoped
someone else would report it. However, that has not happened, so here
it is. It would be nice to see it get into the next release.

BTW, we had some other similar problems, which we fixed by changing a
few casts, but they have not reproduced themselves in 1.34.0 beta.
Perhaps they were only problems for some other compiler, which we are no
longer using.

-- 
Dick Hadsell			914-259-6320  Fax: 914-259-6499
Reply-to:			hadsell_at_[hidden]
Blue Sky Studios                http://www.blueskystudios.com
44 South Broadway, White Plains, NY 10601

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk