diff --git a/base/base_tests/bits_test.cpp b/base/base_tests/bits_test.cpp index 5263246dae..68e9d18048 100644 --- a/base/base_tests/bits_test.cpp +++ b/base/base_tests/bits_test.cpp @@ -1,8 +1,9 @@ #include "testing/testing.hpp" #include "base/bits.hpp" -#include "std/cstdlib.hpp" +#include "base/checked_cast.hpp" +#include #include namespace @@ -37,8 +38,8 @@ UNIT_TEST(PopcountArray32) uint32_t expectedPopCount = 0; for (size_t i = 0; i < v.size(); ++i) expectedPopCount += PopCountSimple(v[i]); - TEST_EQUAL(bits::PopCount(v.empty() ? NULL : &v[0], v.size()), expectedPopCount, - (j, v.size(), expectedPopCount)); + TEST_EQUAL(bits::PopCount(v.empty() ? NULL : &v[0], base::checked_cast(v.size())), + expectedPopCount, (j, v.size(), expectedPopCount)); } } diff --git a/base/base_tests/threads_test.cpp b/base/base_tests/threads_test.cpp index e482cd55bb..98933c7682 100644 --- a/base/base_tests/threads_test.cpp +++ b/base/base_tests/threads_test.cpp @@ -20,7 +20,7 @@ struct GeneratorThread : public threads::IRoutine { for (size_t i = 0; i < MAX_COUNT; ++i) { - m_vec.push_back(i); + m_vec.push_back(static_cast(i)); summ += i; } } diff --git a/coding/coding_tests/dd_vector_test.cpp b/coding/coding_tests/dd_vector_test.cpp index d6cc16f842..56a96aab6e 100644 --- a/coding/coding_tests/dd_vector_test.cpp +++ b/coding/coding_tests/dd_vector_test.cpp @@ -19,8 +19,8 @@ UNIT_TEST(DDVector_Smoke) TEST_EQUAL(2, v[1], ()); TEST_EQUAL(3, v[2], ()); Vector::const_iterator it = v.begin(); - for (size_t i = 0; i < v.size(); ++i, ++it) - TEST_EQUAL(v[i], *it, ()); + for (auto const value : v) + TEST_EQUAL(value, *it++, ()); } UNIT_TEST(DDVector_IncorrectSize) diff --git a/coding/coding_tests/fixed_bits_ddvector_test.cpp b/coding/coding_tests/fixed_bits_ddvector_test.cpp index f50e11a06f..6bf7a70d3b 100644 --- a/coding/coding_tests/fixed_bits_ddvector_test.cpp +++ b/coding/coding_tests/fixed_bits_ddvector_test.cpp @@ -39,7 +39,7 @@ template void TestWithData(vector const & lst) MemReader reader(buf.data(), buf.size()); auto const vec = TVector::Create(reader); - size_t i = 0; + uint32_t i = 0; for (uint32_t actual : lst) { uint32_t expected; diff --git a/coding/coding_tests/var_serial_vector_test.cpp b/coding/coding_tests/var_serial_vector_test.cpp index b2152ffe98..4bed2a5216 100644 --- a/coding/coding_tests/var_serial_vector_test.cpp +++ b/coding/coding_tests/var_serial_vector_test.cpp @@ -107,5 +107,5 @@ UNIT_TEST(EncodeDecode) VarSerialVectorReader reader(memSource); for (size_t i = 0; i < elements.size(); ++i) - TEST_EQUAL(reader.Read(i), elements[i], ()); + TEST_EQUAL(reader.Read(static_cast(i)), elements[i], ()); } diff --git a/indexer/succinct_trie_reader.hpp b/indexer/succinct_trie_reader.hpp index fdef154e7e..d096489646 100644 --- a/indexer/succinct_trie_reader.hpp +++ b/indexer/succinct_trie_reader.hpp @@ -6,6 +6,7 @@ #include "base/assert.hpp" #include "base/bits.hpp" +#include "base/checked_cast.hpp" #include "base/macros.hpp" #include "base/string_utils.hpp" @@ -101,10 +102,10 @@ private: // ids and offsets are delta-encoded id += ReadVarUint>(src); offset += ReadVarUint>(src); - m_finalNodeIndex[id] = i; + m_finalNodeIndex[id] = base::asserted_cast(i); m_offsetTable[i] = offset; } - m_offsetTable[numFinalNodes] = src.Size(); + m_offsetTable[numFinalNodes] = base::checked_cast(src.Size()); m_reader = m_reader.SubReader(src.Pos(), src.Size()); } @@ -148,7 +149,8 @@ public: ASSERT_EQUAL(m_common->GetTopology()[m_nodeBitPosition - 1], 1, (m_nodeBitPosition)); // rank(x) returns the number of ones in [0, x) but we count bit positions from 1 - uint32_t childBitPosition = 2 * m_common->GetTopology().rank(m_nodeBitPosition); + uint32_t childBitPosition = + base::asserted_cast(2 * m_common->GetTopology().rank(m_nodeBitPosition)); if (i == 1) ++childBitPosition; if (childBitPosition > 2 * m_common->NumNodes() || @@ -194,7 +196,7 @@ public: return GoToString(reader, numBits); } - uint32_t NumValues() + size_t NumValues() { if (!m_valuesRead) ReadValues(); @@ -216,7 +218,8 @@ private: return; m_valuesRead = true; // Back to 0-based indices. - uint32_t m_nodeId = m_common->GetTopology().rank(m_nodeBitPosition) - 1; + uint32_t m_nodeId = + base::checked_cast(m_common->GetTopology().rank(m_nodeBitPosition) - 1); if (!m_common->NodeIsFinal(m_nodeId)) return; uint32_t offset = m_common->Offset(m_nodeId); diff --git a/routing/routing_tests/nearest_edge_finder_tests.cpp b/routing/routing_tests/nearest_edge_finder_tests.cpp index 913317febb..549c5cdeb7 100644 --- a/routing/routing_tests/nearest_edge_finder_tests.cpp +++ b/routing/routing_tests/nearest_edge_finder_tests.cpp @@ -4,6 +4,8 @@ #include "routing/nearest_edge_finder.hpp" +#include "base/checked_cast.hpp" + using namespace routing; using namespace routing_test; @@ -16,7 +18,7 @@ void TestNearestOnMock1(m2::PointD const & point, size_t const candidatesCount, NearestEdgeFinder finder(point); for (size_t i = 0; i < graph->GetRoadCount(); ++i) { - FeatureID const featureId = MakeTestFeatureID(i); + FeatureID const featureId = MakeTestFeatureID(base::checked_cast(i)); finder.AddInformationSource(featureId, graph->GetRoadInfo(featureId)); } diff --git a/routing/routing_tests/osrm_router_test.cpp b/routing/routing_tests/osrm_router_test.cpp index d706cf78a3..5718548755 100644 --- a/routing/routing_tests/osrm_router_test.cpp +++ b/routing/routing_tests/osrm_router_test.cpp @@ -16,6 +16,7 @@ #include "defines.hpp" +#include "base/checked_cast.hpp" #include "base/scope_guard.hpp" #include "std/bind.hpp" @@ -117,7 +118,7 @@ void TestMapping(InputDataT const & data, for (size_t i = 0; i < mapping.GetSegmentsCount(); ++i) { - TOsrmNodeId const node = mapping.GetNodeId(i); + TOsrmNodeId const node = mapping.GetNodeId(base::checked_cast(i)); size_t count = 0; mapping.ForEachFtSeg(node, [&] (OsrmMappingTypes::FtSeg const & s) { diff --git a/routing/routing_tests/road_graph_builder.cpp b/routing/routing_tests/road_graph_builder.cpp index 74ee0986d2..37e6ce9fd0 100644 --- a/routing/routing_tests/road_graph_builder.cpp +++ b/routing/routing_tests/road_graph_builder.cpp @@ -4,8 +4,9 @@ #include "indexer/mwm_set.hpp" -#include "base/macros.hpp" +#include "base/checked_cast.hpp" #include "base/logging.hpp" +#include "base/macros.hpp" #include "std/algorithm.hpp" #include "std/shared_ptr.hpp" @@ -89,7 +90,7 @@ void RoadGraphMockSource::ForEachFeatureClosestToCross(m2::PointD const & /* cro ICrossEdgesLoader & edgesLoader) const { for (size_t roadId = 0; roadId < m_roads.size(); ++roadId) - edgesLoader(MakeTestFeatureID(roadId), m_roads[roadId]); + edgesLoader(MakeTestFeatureID(base::checked_cast(roadId)), m_roads[roadId]); } void RoadGraphMockSource::FindClosestEdges(m2::PointD const & point, uint32_t count, diff --git a/routing/routing_tests/turns_generator_test.cpp b/routing/routing_tests/turns_generator_test.cpp index f4f2b2bdfb..5bf6b614e6 100644 --- a/routing/routing_tests/turns_generator_test.cpp +++ b/routing/routing_tests/turns_generator_test.cpp @@ -318,7 +318,8 @@ UNIT_TEST(TestCalculateMercatorDistanceAlongRoute) { vector const points = {{0., 0.}, {0., 1.}, {0., 1.}, {1., 1.}}; - TEST_EQUAL(CalculateMercatorDistanceAlongPath(0, points.size() - 1, points), 2., ()); + uint32_t const lastPointIdx = static_cast(points.size() - 1); + TEST_EQUAL(CalculateMercatorDistanceAlongPath(0, lastPointIdx, points), 2., ()); TEST_EQUAL(CalculateMercatorDistanceAlongPath(1, 1, points), 0., ()); TEST_EQUAL(CalculateMercatorDistanceAlongPath(1, 2, points), 0., ()); TEST_EQUAL(CalculateMercatorDistanceAlongPath(0, 1, points), 1., ()); diff --git a/search/geocoder.cpp b/search/geocoder.cpp index 71cc14c7e5..5caa2c28c6 100644 --- a/search/geocoder.cpp +++ b/search/geocoder.cpp @@ -966,7 +966,7 @@ void Geocoder::MatchPOIsAndBuildings(BaseContext & ctx, size_t curToken) if (m_filter->NeedToFilter(m_postcodes.m_features)) filtered = m_filter->Filter(m_postcodes.m_features); filtered.ForEach([&](uint64_t bit) { - uint32_t const featureId = base::asserted_cast(bit); + auto const featureId = base::asserted_cast(bit); SearchModel::SearchType searchType; if (GetSearchTypeInGeocoding(ctx, featureId, searchType)) { @@ -1007,7 +1007,7 @@ void Geocoder::MatchPOIsAndBuildings(BaseContext & ctx, size_t curToken) vector features; m_postcodes.m_features.ForEach([&features](uint64_t bit) { - features.push_back(base::asserted_cast(bit)); + features.push_back(base::asserted_cast(bit)); }); layer.m_sortedFeatures = &features; return FindPaths(ctx); @@ -1025,7 +1025,7 @@ void Geocoder::MatchPOIsAndBuildings(BaseContext & ctx, size_t curToken) // any. auto clusterize = [&](uint64_t bit) { - uint32_t const featureId = base::asserted_cast(bit); + auto const featureId = base::asserted_cast(bit); SearchModel::SearchType searchType; if (!GetSearchTypeInGeocoding(ctx, featureId, searchType)) return; @@ -1088,7 +1088,7 @@ void Geocoder::MatchPOIsAndBuildings(BaseContext & ctx, size_t curToken) ends[i] = clusters[i].size(); filtered.ForEach([&](uint64_t bit) { - uint32_t const featureId = base::asserted_cast(bit); + auto const featureId = base::asserted_cast(bit); bool found = false; for (size_t i = 0; i < kNumClusters && !found; ++i) { @@ -1278,7 +1278,7 @@ void Geocoder::MatchUnclassified(BaseContext & ctx, size_t curToken) auto emitUnclassified = [&](uint64_t bit) { - uint32_t const featureId = base::asserted_cast(bit); + auto const featureId = base::asserted_cast(bit); SearchModel::SearchType searchType; if (!GetSearchTypeInGeocoding(ctx, featureId, searchType)) return; diff --git a/search/hotels_filter.cpp b/search/hotels_filter.cpp index b3fd8b9785..84cb6bf7e7 100644 --- a/search/hotels_filter.cpp +++ b/search/hotels_filter.cpp @@ -5,6 +5,7 @@ #include "indexer/ftypes_matcher.hpp" #include "base/assert.hpp" +#include "base/checked_cast.hpp" #include "std/algorithm.hpp" @@ -111,7 +112,8 @@ HotelsFilter::Descriptions const & HotelsFilter::GetDescriptions(MwmContext cons auto const hotels = m_hotels.Get(context); auto & descriptions = m_descriptions[mwmId]; - hotels.ForEach([&descriptions, &context](uint32_t id) { + hotels.ForEach([&descriptions, &context](uint64_t bit) { + auto const id = base::asserted_cast(bit); FeatureType ft; Description description; diff --git a/search/locality_scorer.cpp b/search/locality_scorer.cpp index 45136622de..3fecd7ec4b 100644 --- a/search/locality_scorer.cpp +++ b/search/locality_scorer.cpp @@ -4,6 +4,8 @@ #include "search/geocoder_context.hpp" #include "search/token_slice.hpp" +#include "base/checked_cast.hpp" + #include #include #include @@ -62,7 +64,8 @@ void LocalityScorer::GetTopLocalities(MwmSet::MwmId const & countryId, BaseConte // Skip locality candidates that match only numbers. if (!m_params.IsNumberTokens(tokenRange)) { - intersection.ForEach([&](uint32_t featureId) { + intersection.ForEach([&](uint64_t bit) { + auto const featureId = base::asserted_cast(bit); double const prob = static_cast(intersection.PopCount()) / static_cast(unfilteredIntersection.PopCount()); localities.emplace_back(countryId, featureId, tokenRange, prob); diff --git a/search/retrieval.cpp b/search/retrieval.cpp index 60354f721b..666f25cd27 100644 --- a/search/retrieval.cpp +++ b/search/retrieval.cpp @@ -25,6 +25,8 @@ #include "coding/compressed_bit_vector.hpp" #include "coding/reader_wrapper.hpp" +#include "base/checked_cast.hpp" + #include "std/algorithm.hpp" using namespace strings; @@ -224,7 +226,9 @@ unique_ptr RetrieveAddressFeaturesImpl( WithSearchTrieRoot(context.m_value, [&](TrieRoot const & root) { MatchFeaturesInTrie( request, root, - [&holder](uint32_t featureIndex) { return !holder.ModifiedOrDeleted(featureIndex); }, + [&holder](uint64_t featureIndex) { + return !holder.ModifiedOrDeleted(base::asserted_cast(featureIndex)); + }, collector); }); @@ -247,7 +251,9 @@ unique_ptr RetrievePostcodeFeaturesImpl( WithSearchTrieRoot(context.m_value, [&](TrieRoot const & root) { MatchPostcodesInTrie( slice, root, - [&holder](uint32_t featureIndex) { return !holder.ModifiedOrDeleted(featureIndex); }, + [&holder](uint64_t featureIndex) { + return !holder.ModifiedOrDeleted(base::asserted_cast(featureIndex)); + }, collector); }); holder.ForEachModifiedOrCreated([&](FeatureType & ft, uint64_t index) {