From aa4dafcc46f0740c28583014c7b92649eee0df6d Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Mon, 12 Jun 2017 13:33:47 -0400 Subject: [PATCH] Silence sign conversion warnings --- date.h | 54 +++++++++---------- iso_week.h | 7 +-- test/date_test/year_month_day_last.pass.cpp | 2 +- test/date_test/year_month_weekday.pass.cpp | 2 +- .../year_month_weekday_last.pass.cpp | 2 +- tz.cpp | 18 ++++--- 6 files changed, 45 insertions(+), 40 deletions(-) diff --git a/date.h b/date.h index 2793fbc..3f6941e 100644 --- a/date.h +++ b/date.h @@ -5249,7 +5249,7 @@ read_unsigned(std::basic_istream& is, unsigned m = 1, unsigned M break; (void)is.get(); ++count; - x = 10*x + (c - '0'); + x = 10*x + static_cast(c - '0'); if (count == M) break; } @@ -5593,7 +5593,7 @@ from_stream(std::basic_istream& 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(width)}); } else { @@ -5633,8 +5633,8 @@ from_stream(std::basic_istream& 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(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& 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(width)}); else if (modified == CharT{'O'}) { ios_base::iostate err = ios_base::goodbit; @@ -5676,7 +5676,7 @@ from_stream(std::basic_istream& 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(width)}); if (!is.fail()) h = hours{H}; } @@ -5703,7 +5703,7 @@ from_stream(std::basic_istream& 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(width)}); if (I != not_a_hour_12_value) { if (!(1 <= I && I <= 12)) @@ -5726,7 +5726,7 @@ from_stream(std::basic_istream& 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(width)}); else read(is, CharT{'%'}, width, modified, *fmt); command = nullptr; @@ -5742,7 +5742,7 @@ from_stream(std::basic_istream& 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(width)}); if (!is.fail()) min = minutes{M}; } @@ -5767,7 +5767,7 @@ from_stream(std::basic_istream& 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(width)}); else if (modified == CharT{'O'}) { ios_base::iostate err = ios_base::goodbit; @@ -5893,7 +5893,7 @@ from_stream(std::basic_istream& is, const CharT* fmt, using dfs = detail::decimal_format_seconds; 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(width)}); if (!is.fail()) s = round(duration{S}); } @@ -5946,7 +5946,7 @@ from_stream(std::basic_istream& 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(width)}); else if (modified == CharT{'E'}) { ios_base::iostate err = ios_base::goodbit; @@ -5971,7 +5971,7 @@ from_stream(std::basic_istream& 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(width)}); else { ios_base::iostate err = ios_base::goodbit; @@ -5991,7 +5991,7 @@ from_stream(std::basic_istream& 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(width)}); else read(is, CharT{'%'}, width, modified, *fmt); command = nullptr; @@ -6005,7 +6005,7 @@ from_stream(std::basic_istream& 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(width)}); else read(is, CharT{'%'}, width, modified, *fmt); command = nullptr; @@ -6019,7 +6019,7 @@ from_stream(std::basic_istream& 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(width)}); else read(is, CharT{'%'}, width, modified, *fmt); command = nullptr; @@ -6033,7 +6033,7 @@ from_stream(std::basic_istream& 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(width)}); else read(is, CharT{'%'}, width, modified, *fmt); command = nullptr; @@ -6047,7 +6047,7 @@ from_stream(std::basic_istream& 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(width)}); else read(is, CharT{'%'}, width, modified, *fmt); command = nullptr; @@ -6063,7 +6063,7 @@ from_stream(std::basic_istream& 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(width)}); if (!is.fail() && *fmt == 'u') { if (wd == 7) @@ -6288,11 +6288,11 @@ from_stream(std::basic_istream& is, const CharT* fmt, goto broken; if (m == 0) m = static_cast(static_cast(ymd.month())); - else if (month(m) != ymd.month()) + else if (month(static_cast(m)) != ymd.month()) goto broken; if (d == 0) d = static_cast(static_cast(ymd.day())); - else if (day(d) != ymd.day()) + else if (day(static_cast(d)) != ymd.day()) goto broken; } if (j != 0 && Y != not_a_year) @@ -6300,11 +6300,11 @@ from_stream(std::basic_istream& is, const CharT* fmt, auto ymd = year_month_day{local_days(year{Y}/1/1) + days{j-1}}; if (m == 0) m = static_cast(static_cast(ymd.month())); - else if (month(m) != ymd.month()) + else if (month(static_cast(m)) != ymd.month()) goto broken; if (d == 0) d = static_cast(static_cast(ymd.day())); - else if (day(d) != ymd.day()) + else if (day(static_cast(d)) != ymd.day()) goto broken; } if (U != not_a_week_num && Y != not_a_year) @@ -6322,11 +6322,11 @@ from_stream(std::basic_istream& is, const CharT* fmt, goto broken; if (m == 0) m = static_cast(static_cast(ymd.month())); - else if (month(m) != ymd.month()) + else if (month(static_cast(m)) != ymd.month()) goto broken; if (d == 0) d = static_cast(static_cast(ymd.day())); - else if (day(d) != ymd.day()) + else if (day(static_cast(d)) != ymd.day()) goto broken; } if (W != not_a_week_num && Y != not_a_year) @@ -6344,11 +6344,11 @@ from_stream(std::basic_istream& is, const CharT* fmt, goto broken; if (m == 0) m = static_cast(static_cast(ymd.month())); - else if (month(m) != ymd.month()) + else if (month(static_cast(m)) != ymd.month()) goto broken; if (d == 0) d = static_cast(static_cast(ymd.day())); - else if (day(d) != ymd.day()) + else if (day(static_cast(d)) != ymd.day()) goto broken; } auto ymd = year{Y}/m/d; diff --git a/iso_week.h b/iso_week.h index 3e76a15..bbb2c8d 100644 --- a/iso_week.h +++ b/iso_week.h @@ -1017,7 +1017,7 @@ year_lastweek::weeknum() const NOEXCEPT const auto y = date::year{static_cast(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(s1-s0).count()); + return iso_week::weeknum(static_cast(date::trunc(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(dp - start).count() + 1); + const auto wn = iso_week::weeknum( + static_cast(date::trunc(dp - start).count() + 1)); return {iso_week::year(static_cast(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(wn)); } CONSTCD11 diff --git a/test/date_test/year_month_day_last.pass.cpp b/test/date_test/year_month_day_last.pass.cpp index 281541d..41f1858 100644 --- a/test/date_test/year_month_day_last.pass.cpp +++ b/test/date_test/year_month_day_last.pass.cpp @@ -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); diff --git a/test/date_test/year_month_weekday.pass.cpp b/test/date_test/year_month_weekday.pass.cpp index 2630705..6e466b0 100644 --- a/test/date_test/year_month_weekday.pass.cpp +++ b/test/date_test/year_month_weekday.pass.cpp @@ -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); diff --git a/test/date_test/year_month_weekday_last.pass.cpp b/test/date_test/year_month_weekday_last.pass.cpp index bbdbdda..3abe113 100644 --- a/test/date_test/year_month_weekday_last.pass.cpp +++ b/test/date_test/year_month_weekday_last.pass.cpp @@ -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); diff --git a/tz.cpp b/tz.cpp index cdfa67f..1880c7b 100644 --- a/tz.cpp +++ b/tz.cpp @@ -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 transitions; - transitions.reserve(tzh_timecnt); + transitions.reserve(static_cast(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 indices; - indices.reserve(tzh_timecnt); + indices.reserve(static_cast(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 ttinfos; - ttinfos.reserve(tzh_typecnt); + ttinfos.reserve(static_cast(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(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(userp); auto realsize = size * nmemb; - of.write(contents, realsize); + of.write(contents, static_cast(realsize)); return realsize; }; curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, write_cb);