diff --git a/base/checked_cast.hpp b/base/checked_cast.hpp new file mode 100644 index 0000000000..363840c785 --- /dev/null +++ b/base/checked_cast.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include "base/assert.hpp" + +namespace base +{ +template +ReturnType checked_cast(ParameterType v) +{ + CHECK_EQUAL(static_cast(static_cast(v)), v, ()); + return static_cast(v); +} + +template +ReturnType asserted_cast(ParameterType v) +{ + ASSERT_EQUAL(static_cast(static_cast(v)), v, ()); + return static_cast(v); +} +} // namespace base diff --git a/base/condition.cpp b/base/condition.cpp index 1082a04346..2be49f0e27 100644 --- a/base/condition.cpp +++ b/base/condition.cpp @@ -8,6 +8,7 @@ #include #include +#include namespace threads { @@ -47,7 +48,7 @@ namespace threads bool Condition::Wait(unsigned ms) { - if (ms == -1) + if (ms == std::numeric_limits::max()) { Wait(); return false; diff --git a/base/stl_iterator.hpp b/base/stl_iterator.hpp index a409f08b5f..4637dc9704 100644 --- a/base/stl_iterator.hpp +++ b/base/stl_iterator.hpp @@ -1,6 +1,15 @@ #pragma once -#include +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wshorten-64-to-32" +#endif + +#include "3party/boost/boost/iterator/iterator_facade.hpp" + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif namespace detail { diff --git a/editor/changeset_wrapper.cpp b/editor/changeset_wrapper.cpp index d161b4332b..73b6c39a03 100644 --- a/editor/changeset_wrapper.cpp +++ b/editor/changeset_wrapper.cpp @@ -281,8 +281,8 @@ string ChangesetWrapper::TypeCountToString(TTypeCount const & typeCount) }); ostringstream ss; - auto const limit = min(size_t(3), items.size()); - for (auto i = 0; i < limit; ++i) + size_t const limit = min(size_t(3), items.size()); + for (size_t i = 0; i < limit; ++i) { if (i > 0) { diff --git a/indexer/centers_table.cpp b/indexer/centers_table.cpp index f0a1fa7d6a..1659c6a83a 100644 --- a/indexer/centers_table.cpp +++ b/indexer/centers_table.cpp @@ -14,6 +14,7 @@ #include "coding/writer.hpp" #include "base/assert.hpp" +#include "base/checked_cast.hpp" #include "base/logging.hpp" #include "std/unordered_map.hpp" @@ -151,10 +152,10 @@ public: { entry.resize(kBlockSize); - uint32_t const start = m_offsets.select(base); - uint32_t const end = base + 1 < m_offsets.num_ones() - ? m_offsets.select(base + 1) - : m_header.m_endOffset - m_header.m_deltasOffset; + auto const start = m_offsets.select(base); + auto const end = base + 1 < m_offsets.num_ones() + ? m_offsets.select(base + 1) + : m_header.m_endOffset - m_header.m_deltasOffset; vector data(end - start); @@ -297,7 +298,7 @@ void CentersTableBuilder::Freeze(Writer & writer) const MemWriter> writer(deltas); for (size_t i = 0; i < m_centers.size(); i += CentersTableV0::kBlockSize) { - offsets.push_back(deltas.size()); + offsets.push_back(static_cast(deltas.size())); uint64_t delta = EncodeDelta(m_centers[i], m_codingParams.GetBasePoint()); WriteVarUint(writer, delta); @@ -315,15 +316,15 @@ void CentersTableBuilder::Freeze(Writer & writer) const for (auto const & offset : offsets) builder.push_back(offset); - header.m_positionsOffset = writer.Pos() - startOffset; + header.m_positionsOffset = base::checked_cast(writer.Pos() - startOffset); coding::FreezeVisitor visitor(writer); succinct::elias_fano(&builder).map(visitor); } { - header.m_deltasOffset = writer.Pos() - startOffset; + header.m_deltasOffset = base::checked_cast(writer.Pos() - startOffset); writer.Write(deltas.data(), deltas.size()); - header.m_endOffset = writer.Pos() - startOffset; + header.m_endOffset = base::checked_cast(writer.Pos() - startOffset); } int64_t const endOffset = writer.Pos(); diff --git a/indexer/drules_selector.cpp b/indexer/drules_selector.cpp index bacc660246..99c0e1f3c9 100644 --- a/indexer/drules_selector.cpp +++ b/indexer/drules_selector.cpp @@ -97,7 +97,7 @@ private: }; // Feature tag value evaluator for tag 'population' -bool GetPopulation(FeatureType const & ft, uint32_t & population) +bool GetPopulation(FeatureType const & ft, uint64_t & population) { population = ftypes::GetPopulation(ft); return true; @@ -139,14 +139,14 @@ unique_ptr ParseSelector(string const & str) if (e.m_tag == "population") { - int value = 0; - if (!e.m_value.empty() && (!strings::to_int(e.m_value, value) || value < 0)) + uint64_t value = 0; + if (!e.m_value.empty() && !strings::to_uint64(e.m_value, value)) { // bad string format LOG(LDEBUG, ("Invalid selector:", str)); return unique_ptr(); } - return make_unique>(&GetPopulation, e.m_operator, static_cast(value)); + return make_unique>(&GetPopulation, e.m_operator, value); } else if (e.m_tag == "name") { diff --git a/indexer/feature.cpp b/indexer/feature.cpp index 84ecab623f..d5d35dec64 100644 --- a/indexer/feature.cpp +++ b/indexer/feature.cpp @@ -550,7 +550,7 @@ uint8_t FeatureType::GetRank() const return m_params.rank; } -uint32_t FeatureType::GetPopulation() const +uint64_t FeatureType::GetPopulation() const { return feature::RankToPopulation(GetRank()); } diff --git a/indexer/feature.hpp b/indexer/feature.hpp index 874d8bd57a..d580d5eedb 100644 --- a/indexer/feature.hpp +++ b/indexer/feature.hpp @@ -294,7 +294,7 @@ public: //@} uint8_t GetRank() const; - uint32_t GetPopulation() const; + uint64_t GetPopulation() const; string GetRoadNumber() const; inline feature::Metadata const & GetMetadata() const diff --git a/indexer/feature_impl.hpp b/indexer/feature_impl.hpp index ea1ba79950..e5b195620f 100644 --- a/indexer/feature_impl.hpp +++ b/indexer/feature_impl.hpp @@ -14,7 +14,7 @@ namespace feature static int const g_arrWorldScales[] = { 3, 5, 7, 9 }; // 9 = scales::GetUpperWorldScale() static int const g_arrCountryScales[] = { 10, 12, 14, 17 }; // 17 = scales::GetUpperScale() - inline string GetTagForIndex(char const * prefix, int ind) + inline string GetTagForIndex(char const * prefix, size_t ind) { string str; str.reserve(strlen(prefix) + 1); diff --git a/indexer/ftypes_matcher.cpp b/indexer/ftypes_matcher.cpp index d8bd57b50b..ec939f1880 100644 --- a/indexer/ftypes_matcher.cpp +++ b/indexer/ftypes_matcher.cpp @@ -488,9 +488,9 @@ IsLocalityChecker const & IsLocalityChecker::Instance() return inst; } -uint32_t GetPopulation(FeatureType const & ft) +uint64_t GetPopulation(FeatureType const & ft) { - uint32_t population = ft.GetPopulation(); + uint64_t population = ft.GetPopulation(); if (population < 10) { diff --git a/indexer/ftypes_matcher.hpp b/indexer/ftypes_matcher.hpp index 48d1dcfd97..c3d6e02d5d 100644 --- a/indexer/ftypes_matcher.hpp +++ b/indexer/ftypes_matcher.hpp @@ -210,7 +210,7 @@ public: /// @name Get city radius and population. /// @param r Radius in meters. //@{ -uint32_t GetPopulation(FeatureType const & ft); +uint64_t GetPopulation(FeatureType const & ft); double GetRadiusByPopulation(uint32_t p); uint32_t GetPopulationByRadius(double r); //@} diff --git a/indexer/scale_index.hpp b/indexer/scale_index.hpp index d290b1a1a3..5a9a397544 100644 --- a/indexer/scale_index.hpp +++ b/indexer/scale_index.hpp @@ -53,7 +53,7 @@ public: ReaderSource source(reader); VarSerialVectorReader treesReader(source); - for (int i = 0; i < treesReader.Size(); ++i) + for (uint32_t i = 0; i < treesReader.Size(); ++i) m_IndexForScale.push_back(factory.CreateIndex(treesReader.SubReader(i))); } diff --git a/platform/apple_location_service.mm b/platform/apple_location_service.mm index cb7da3a328..a26c85eaf5 100644 --- a/platform/apple_location_service.mm +++ b/platform/apple_location_service.mm @@ -88,6 +88,7 @@ public: - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { + UNUSED_VALUE(manager); GpsInfo newInfo; [LocationManagerWrapper location:locations.firstObject toGpsInfo:newInfo]; m_service->OnLocationUpdate(newInfo); @@ -96,6 +97,7 @@ public: - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { + UNUSED_VALUE(manager); LOG(LWARNING, ("locationManager failed with error", error.code, [error.description UTF8String])); if (error.code == kCLErrorDenied) diff --git a/search/ranking_utils.hpp b/search/ranking_utils.hpp index 1af9bbe6ce..d247bc4ef9 100644 --- a/search/ranking_utils.hpp +++ b/search/ranking_utils.hpp @@ -61,10 +61,10 @@ NameScore GetNameScore(vector const & tokens, TSlice const & bool const lastTokenIsPrefix = slice.IsPrefix(m - 1); NameScore score = NAME_SCORE_ZERO; - for (int offset = 0; offset + m <= n; ++offset) + for (size_t offset = 0; offset + m <= n; ++offset) { bool match = true; - for (int i = 0; i < m - 1 && match; ++i) + for (size_t i = 0; i < m - 1 && match; ++i) match = match && impl::Match(slice.Get(i), tokens[offset + i]); if (!match) continue; diff --git a/traffic/traffic_info.cpp b/traffic/traffic_info.cpp index ffa122fae7..48c2600af0 100644 --- a/traffic/traffic_info.cpp +++ b/traffic/traffic_info.cpp @@ -511,8 +511,8 @@ TrafficInfo::ServerDataStatus TrafficInfo::ProcessFailure(platform::HttpClient c { case 404: /* Not Found */ { - int64_t version = 0; - strings::to_int64(request.ServerResponse().c_str(), version); + uint64_t version = 0; + strings::to_uint64(request.ServerResponse().c_str(), version); if (version > mwmVersion && version <= m_currentDataVersion) m_availability = Availability::ExpiredData;