Silence sign conversion warnings

This commit is contained in:
Howard Hinnant 2017-06-12 13:33:47 -04:00
parent cc81c9ea50
commit aa4dafcc46
6 changed files with 45 additions and 40 deletions

54
date.h
View File

@ -5249,7 +5249,7 @@ read_unsigned(std::basic_istream<CharT, Traits>& is, unsigned m = 1, unsigned M
break;
(void)is.get();
++count;
x = 10*x + (c - '0');
x = 10*x + static_cast<unsigned>(c - '0');
if (count == M)
break;
}
@ -5593,7 +5593,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
{
if (modified == CharT{})
{
read(is, rs{C, 1, width == -1 ? 2u : width});
read(is, rs{C, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
}
else
{
@ -5633,8 +5633,8 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (command)
{
if (modified == CharT{})
read(is, rs{Y, 1, width == -1 ? 4u : width}, CharT{'-'},
ru{m, 1, 2}, CharT{'-'}, ru{d, 1, 2});
read(is, rs{Y, 1, width == -1 ? 4u : static_cast<unsigned>(width)},
CharT{'-'}, ru{m, 1, 2}, CharT{'-'}, ru{d, 1, 2});
else
read(is, CharT{'%'}, width, modified, *fmt);
command = nullptr;
@ -5649,7 +5649,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (command)
{
if (modified == CharT{})
read(is, rs{d, 1, width == -1 ? 2u : width});
read(is, rs{d, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
else if (modified == CharT{'O'})
{
ios_base::iostate err = ios_base::goodbit;
@ -5676,7 +5676,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (modified == CharT{})
{
int H;
read(is, ru{H, 1, width == -1 ? 2u : width});
read(is, ru{H, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
if (!is.fail())
h = hours{H};
}
@ -5703,7 +5703,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (modified == CharT{})
{
// reads in an hour into I, but most be in [1, 12]
read(is, rs{I, 1, width == -1 ? 2u : width});
read(is, rs{I, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
if (I != not_a_hour_12_value)
{
if (!(1 <= I && I <= 12))
@ -5726,7 +5726,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (command)
{
if (modified == CharT{})
read(is, ru{j, 1, width == -1 ? 3u : width});
read(is, ru{j, 1, width == -1 ? 3u : static_cast<unsigned>(width)});
else
read(is, CharT{'%'}, width, modified, *fmt);
command = nullptr;
@ -5742,7 +5742,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (modified == CharT{})
{
int M;
read(is, ru{M, 1, width == -1 ? 2u : width});
read(is, ru{M, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
if (!is.fail())
min = minutes{M};
}
@ -5767,7 +5767,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (command)
{
if (modified == CharT{})
read(is, rs{m, 1, width == -1 ? 2u : width});
read(is, rs{m, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
else if (modified == CharT{'O'})
{
ios_base::iostate err = ios_base::goodbit;
@ -5893,7 +5893,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
using dfs = detail::decimal_format_seconds<Duration>;
CONSTDATA auto w = Duration::period::den == 1 ? 2 : 3 + dfs::width;
long double S;
read(is, rld{S, 1, width == -1 ? w : width});
read(is, rld{S, 1, width == -1 ? w : static_cast<unsigned>(width)});
if (!is.fail())
s = round<Duration>(duration<long double>{S});
}
@ -5946,7 +5946,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (command)
{
if (modified == CharT{})
read(is, rs{Y, 1, width == -1 ? 4u : width});
read(is, rs{Y, 1, width == -1 ? 4u : static_cast<unsigned>(width)});
else if (modified == CharT{'E'})
{
ios_base::iostate err = ios_base::goodbit;
@ -5971,7 +5971,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (command)
{
if (modified == CharT{})
read(is, ru{y, 1, width == -1 ? 2u : width});
read(is, ru{y, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
else
{
ios_base::iostate err = ios_base::goodbit;
@ -5991,7 +5991,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (command)
{
if (modified == CharT{})
read(is, ru{g, 1, width == -1 ? 2u : width});
read(is, ru{g, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
else
read(is, CharT{'%'}, width, modified, *fmt);
command = nullptr;
@ -6005,7 +6005,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (command)
{
if (modified == CharT{})
read(is, rs{G, 1, width == -1 ? 4u : width});
read(is, rs{G, 1, width == -1 ? 4u : static_cast<unsigned>(width)});
else
read(is, CharT{'%'}, width, modified, *fmt);
command = nullptr;
@ -6019,7 +6019,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (command)
{
if (modified == CharT{})
read(is, ru{U, 1, width == -1 ? 2u : width});
read(is, ru{U, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
else
read(is, CharT{'%'}, width, modified, *fmt);
command = nullptr;
@ -6033,7 +6033,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (command)
{
if (modified == CharT{})
read(is, ru{V, 1, width == -1 ? 2u : width});
read(is, ru{V, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
else
read(is, CharT{'%'}, width, modified, *fmt);
command = nullptr;
@ -6047,7 +6047,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
if (command)
{
if (modified == CharT{})
read(is, ru{W, 1, width == -1 ? 2u : width});
read(is, ru{W, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
else
read(is, CharT{'%'}, width, modified, *fmt);
command = nullptr;
@ -6063,7 +6063,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
{
if (modified == CharT{})
{
read(is, ru{wd, 1, width == -1 ? 1u : width});
read(is, ru{wd, 1, width == -1 ? 1u : static_cast<unsigned>(width)});
if (!is.fail() && *fmt == 'u')
{
if (wd == 7)
@ -6288,11 +6288,11 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
goto broken;
if (m == 0)
m = static_cast<int>(static_cast<unsigned>(ymd.month()));
else if (month(m) != ymd.month())
else if (month(static_cast<unsigned>(m)) != ymd.month())
goto broken;
if (d == 0)
d = static_cast<int>(static_cast<unsigned>(ymd.day()));
else if (day(d) != ymd.day())
else if (day(static_cast<unsigned>(d)) != ymd.day())
goto broken;
}
if (j != 0 && Y != not_a_year)
@ -6300,11 +6300,11 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
auto ymd = year_month_day{local_days(year{Y}/1/1) + days{j-1}};
if (m == 0)
m = static_cast<int>(static_cast<unsigned>(ymd.month()));
else if (month(m) != ymd.month())
else if (month(static_cast<unsigned>(m)) != ymd.month())
goto broken;
if (d == 0)
d = static_cast<int>(static_cast<unsigned>(ymd.day()));
else if (day(d) != ymd.day())
else if (day(static_cast<unsigned>(d)) != ymd.day())
goto broken;
}
if (U != not_a_week_num && Y != not_a_year)
@ -6322,11 +6322,11 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
goto broken;
if (m == 0)
m = static_cast<int>(static_cast<unsigned>(ymd.month()));
else if (month(m) != ymd.month())
else if (month(static_cast<unsigned>(m)) != ymd.month())
goto broken;
if (d == 0)
d = static_cast<int>(static_cast<unsigned>(ymd.day()));
else if (day(d) != ymd.day())
else if (day(static_cast<unsigned>(d)) != ymd.day())
goto broken;
}
if (W != not_a_week_num && Y != not_a_year)
@ -6344,11 +6344,11 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
goto broken;
if (m == 0)
m = static_cast<int>(static_cast<unsigned>(ymd.month()));
else if (month(m) != ymd.month())
else if (month(static_cast<unsigned>(m)) != ymd.month())
goto broken;
if (d == 0)
d = static_cast<int>(static_cast<unsigned>(ymd.day()));
else if (day(d) != ymd.day())
else if (day(static_cast<unsigned>(d)) != ymd.day())
goto broken;
}
auto ymd = year{Y}/m/d;

View File

@ -1017,7 +1017,7 @@ year_lastweek::weeknum() const NOEXCEPT
const auto y = date::year{static_cast<int>(y_)};
const auto s0 = sys_days((y-years{1})/12/date::thu[date::last]);
const auto s1 = sys_days(y/12/date::thu[date::last]);
return iso_week::weeknum(date::trunc<weeks>(s1-s0).count());
return iso_week::weeknum(static_cast<unsigned>(date::trunc<weeks>(s1-s0).count()));
}
CONSTCD11 inline bool year_lastweek::ok() const NOEXCEPT {return y_.ok();}
@ -1505,7 +1505,8 @@ year_weeknum_weekday::from_days(days d) NOEXCEPT
--y;
start = sys_days((y - date::years{1})/date::dec/date::thu[date::last]) + (mon-thu);
}
const auto wn = iso_week::weeknum(date::trunc<weeks>(dp - start).count() + 1);
const auto wn = iso_week::weeknum(
static_cast<unsigned>(date::trunc<weeks>(dp - start).count() + 1));
return {iso_week::year(static_cast<int>(y)), wn, wd};
}
@ -1608,7 +1609,7 @@ inline
year_weeknum
operator/(const year& y, int wn) NOEXCEPT
{
return y/weeknum(wn);
return y/weeknum(static_cast<unsigned>(wn));
}
CONSTCD11

View File

@ -105,7 +105,7 @@ test_arithmetic()
for (int y1 = 2010; y1 <= 2015; ++y1)
{
for (unsigned m1 = 1; m1 <= 12; ++m1)
for (int m1 = 1; m1 <= 12; ++m1)
{
auto ymd1 = last/m1/y1;;
auto ymd2 = ymd1 + months(24);

View File

@ -106,7 +106,7 @@ test_arithmetic()
for (int y1 = 2010; y1 <= 2015; ++y1)
{
for (unsigned m1 = 1; m1 <= 12; ++m1)
for (int m1 = 1; m1 <= 12; ++m1)
{
auto ymd1 = mon[2]/m1/y1;;
auto ymd2 = ymd1 + months(24);

View File

@ -101,7 +101,7 @@ test_arithmetic()
for (int y1 = 2010; y1 <= 2015; ++y1)
{
for (unsigned m1 = 1; m1 <= 12; ++m1)
for (int m1 = 1; m1 <= 12; ++m1)
{
auto ymd1 = mon[last]/m1/y1;;
auto ymd2 = ymd1 + months(24);

18
tz.cpp
View File

@ -304,9 +304,13 @@ CONSTDATA auto max_year = date::year::max();
CONSTDATA auto min_day = date::jan/1;
CONSTDATA auto max_day = date::dec/31;
#if USE_OS_TZDB
CONSTCD14 const sys_seconds min_seconds = sys_days(min_year/min_day);
CONSTCD14 const sys_seconds max_seconds = sys_days(max_year/max_day);
#endif // USE_OS_TZDB
#ifndef _WIN32
constexpr const char tz_dir[] = "/usr/share/zoneinfo";
#endif
@ -1549,7 +1553,7 @@ load_transitions(std::istream& inf, std::int32_t tzh_timecnt)
// Read transitions
using namespace std::chrono;
std::vector<detail::transition> transitions;
transitions.reserve(tzh_timecnt);
transitions.reserve(static_cast<unsigned>(tzh_timecnt));
for (std::int32_t i = 0; i < tzh_timecnt; ++i)
{
TimeType t;
@ -1568,7 +1572,7 @@ load_indices(std::istream& inf, std::int32_t tzh_timecnt)
{
// Read indices
std::vector<std::uint8_t> indices;
indices.reserve(tzh_timecnt);
indices.reserve(static_cast<unsigned>(tzh_timecnt));
for (std::int32_t i = 0; i < tzh_timecnt; ++i)
{
std::uint8_t t;
@ -1584,7 +1588,7 @@ load_ttinfo(std::istream& inf, std::int32_t tzh_typecnt)
{
// Read ttinfo
std::vector<ttinfo> ttinfos;
ttinfos.reserve(tzh_typecnt);
ttinfos.reserve(static_cast<unsigned>(tzh_typecnt));
for (std::int32_t i = 0; i < tzh_typecnt; ++i)
{
ttinfo t;
@ -1601,7 +1605,7 @@ load_abbreviations(std::istream& inf, std::int32_t tzh_charcnt)
{
// Read abbreviations
std::string abbrev;
abbrev.resize(tzh_charcnt, '\0');
abbrev.resize(static_cast<unsigned>(tzh_charcnt), '\0');
inf.read(&abbrev[0], tzh_charcnt);
return abbrev;
}
@ -1700,7 +1704,7 @@ time_zone::load_data(std::istream& inf,
abbrev.c_str() + info.tt_abbrind,
info.tt_isdst != 0});
}
auto i = 0;
auto i = 0u;
if (transitions_.empty() || transitions_.front().timepoint != min_seconds)
{
transitions_.emplace(transitions_.begin(), min_seconds);
@ -1712,7 +1716,7 @@ time_zone::load_data(std::istream& inf,
transitions_[i].info = &*tf;
++i;
}
for (auto j = 0; i < transitions_.size(); ++i, ++j)
for (auto j = 0u; i < transitions_.size(); ++i, ++j)
transitions_[i].info = ttinfos_.data() + indices[j];
}
@ -2512,7 +2516,7 @@ download_to_file(const std::string& url, const std::string& local_filename,
{
auto& of = *static_cast<std::ofstream*>(userp);
auto realsize = size * nmemb;
of.write(contents, realsize);
of.write(contents, static_cast<std::streamsize>(realsize));
return realsize;
};
curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, write_cb);