Opened 14 years ago

Closed 12 years ago

Last modified 10 years ago

#2757 closed Patches (fixed)

Warning C4244: conversion from 'int' to 'unsigned short' in microsec_time_clock.hpp line 103

Reported by: james@… Owned by: az_sw_dude
Milestone: Boost 1.43.0 Component: date_time
Version: Boost Development Trunk Severity: Cosmetic
Keywords: Cc:

Description

With Visual Studio 2005, the compiler raises the following warning:

c:\programme\boost\boost_1_38_0\boost\date_time\microsec_time_clock.hpp(103) : warning C4244: 'argument' : conversion from 'int' to 'unsigned short', possible loss of data

The members of the std::tm struct are ints, but the greg_year type is declared as unsigned short in greg_year.hpp.

Change History (9)

comment:1 by james@…, 14 years ago

Line 99ff:

...
  std::tm curr;
  std::tm* curr_ptr = converter(&t, &curr);
  date_type d(static_cast<date_type::year_type::value_type>(curr_ptr->tm_year + 1900),
    static_cast<date_type::month_type::value_type>(curr_ptr->tm_mon + 1),
    static_cast<date_type::day_type::value_type>(curr_ptr->tm_mday));
...

This will suppress this warning.

comment:2 by gareth.sylvester-bradley@…, 13 years ago

Type: BugsPatches

FWIW, this problem still applies to current release (1.41.0) and trunk. The file <boost/date_time/microsec_time_clock.hpp> ends up included in a lot of situations, e.g. via Boost.Thread, so I see this warning many many many times in my code base.

I independently reinvented the same patch as the OP. Unfortunately I didn't think to check Trac until I had one - any chance of this being applied so nobody else has to..?

comment:3 by james@…, 13 years ago

Milestone: Boost 1.39.0Boost 1.43.0
Version: Boost 1.38.0Boost Development Trunk

Please fix this... The warnings are annoying.

comment:4 by Andrey Semashev, 13 years ago

(In [61293]) Refs #2757. Added explicit casts to avoid warnings on MSVC.

comment:5 by gareth.sylvester-bradley@…, 13 years ago

Thank you Andrey!

I assume this will have to wait for merge until 1.44.0?

comment:6 by Andrey Semashev, 13 years ago

Yes, the problem is not that critical to push it for 1.43.

comment:7 by Andrey Semashev, 12 years ago

Resolution: fixed
Status: newclosed

(In [61892]) Fixes #2757. Added explicit casts to avoid warnings on MSVC.

comment:8 by michael.cowperthwaite@…, 10 years ago

Seeing this warning with Boost 1.49, MSVS 2008. The warnings are not suppressible using MS's #pragma warning feature.

in reply to:  8 comment:9 by anonymous, 10 years ago

Replying to michael.cowperthwaite@…:

Seeing this warning with Boost 1.49, MSVS 2008. The warnings are not suppressible using MS's #pragma warning feature.

Sorry, I was wrong; warning at different location. See new ticket #6936.

Note: See TracTickets for help on using tickets.