diff options
author | Maxim Pimenov <m@maps.me> | 2017-03-27 16:52:31 +0300 |
---|---|---|
committer | Maxim Pimenov <m@maps.me> | 2017-03-27 17:02:46 +0300 |
commit | 5c3f3080726b6e5551bea70f1470b5a52580edca (patch) | |
tree | 0c4f3fca0457923fe35efc82b76cd2a20246979a | |
parent | e6bbc3477d4836b2421f0b0d84c7b954b7f73e11 (diff) |
Fixed some warnings.
-rw-r--r-- | base/base_tests/bits_test.cpp | 7 | ||||
-rw-r--r-- | base/base_tests/threads_test.cpp | 2 | ||||
-rw-r--r-- | coding/coding_tests/dd_vector_test.cpp | 2 | ||||
-rw-r--r-- | coding/coding_tests/fixed_bits_ddvector_test.cpp | 2 | ||||
-rw-r--r-- | coding/coding_tests/var_serial_vector_test.cpp | 2 | ||||
-rw-r--r-- | indexer/succinct_trie_reader.hpp | 13 | ||||
-rw-r--r-- | routing/routing_tests/nearest_edge_finder_tests.cpp | 4 | ||||
-rw-r--r-- | routing/routing_tests/osrm_router_test.cpp | 3 | ||||
-rw-r--r-- | routing/routing_tests/road_graph_builder.cpp | 2 | ||||
-rw-r--r-- | routing/routing_tests/turns_generator_test.cpp | 3 | ||||
-rw-r--r-- | search/geocoder.cpp | 2 | ||||
-rw-r--r-- | search/hotels_filter.cpp | 4 | ||||
-rw-r--r-- | search/locality_scorer.cpp | 5 | ||||
-rw-r--r-- | search/retrieval.cpp | 10 |
14 files changed, 40 insertions, 21 deletions
diff --git a/base/base_tests/bits_test.cpp b/base/base_tests/bits_test.cpp index 5263246dae..14c9cada97 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 <cstdlib> #include <vector> 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::asserted_cast<uint32_t>(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<int>(i)); summ += i; } } diff --git a/coding/coding_tests/dd_vector_test.cpp b/coding/coding_tests/dd_vector_test.cpp index d6cc16f842..c6993997e3 100644 --- a/coding/coding_tests/dd_vector_test.cpp +++ b/coding/coding_tests/dd_vector_test.cpp @@ -19,7 +19,7 @@ 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) + for (Vector::size_type i = 0; i < v.size(); ++i, ++it) TEST_EQUAL(v[i], *it, ()); } 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 <size_t Bits> void TestWithData(vector<uint32_t> 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<MemReader> reader(memSource); for (size_t i = 0; i < elements.size(); ++i) - TEST_EQUAL(reader.Read(i), elements[i], ()); + TEST_EQUAL(reader.Read(static_cast<uint32_t>(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<uint32_t, ReaderSource<TReader>>(src); offset += ReadVarUint<uint32_t, ReaderSource<TReader>>(src); - m_finalNodeIndex[id] = i; + m_finalNodeIndex[id] = base::asserted_cast<int>(i); m_offsetTable[i] = offset; } - m_offsetTable[numFinalNodes] = src.Size(); + m_offsetTable[numFinalNodes] = base::checked_cast<uint32_t>(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<uint32_t>(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<uint32_t>(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..e99ff1a0d8 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::asserted_cast<uint32_t>(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..52961d5f6d 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::asserted_cast<uint32_t>(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..0d75c52ba8 100644 --- a/routing/routing_tests/road_graph_builder.cpp +++ b/routing/routing_tests/road_graph_builder.cpp @@ -88,7 +88,7 @@ double RoadGraphMockSource::GetMaxSpeedKMPH() const void RoadGraphMockSource::ForEachFeatureClosestToCross(m2::PointD const & /* cross */, ICrossEdgesLoader & edgesLoader) const { - for (size_t roadId = 0; roadId < m_roads.size(); ++roadId) + for (uint32_t roadId = 0; roadId < m_roads.size(); ++roadId) edgesLoader(MakeTestFeatureID(roadId), m_roads[roadId]); } 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<m2::PointD> 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<uint32_t>(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..8e9ef25a3c 100644 --- a/search/geocoder.cpp +++ b/search/geocoder.cpp @@ -1007,7 +1007,7 @@ void Geocoder::MatchPOIsAndBuildings(BaseContext & ctx, size_t curToken) vector<uint32_t> features; m_postcodes.m_features.ForEach([&features](uint64_t bit) { - features.push_back(base::asserted_cast<uint32_t>(bit)); + features.push_back(base::asserted_cast<uint32_t>(bit)); }); layer.m_sortedFeatures = &features; return FindPaths(ctx); diff --git a/search/hotels_filter.cpp b/search/hotels_filter.cpp index b3fd8b9785..0499eb7e3d 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) { + uint32_t const id = base::asserted_cast<uint32_t>(bit); FeatureType ft; Description description; diff --git a/search/locality_scorer.cpp b/search/locality_scorer.cpp index 45136622de..58f4442d51 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 <algorithm> #include <sstream> #include <unordered_set> @@ -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) { + uint32_t const featureId = base::asserted_cast<uint32_t>(bit); double const prob = static_cast<double>(intersection.PopCount()) / static_cast<double>(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<coding::CompressedBitVector> RetrieveAddressFeaturesImpl( WithSearchTrieRoot<Value>(context.m_value, [&](TrieRoot<Value> const & root) { MatchFeaturesInTrie( request, root, - [&holder](uint32_t featureIndex) { return !holder.ModifiedOrDeleted(featureIndex); }, + [&holder](uint64_t featureIndex) { + return !holder.ModifiedOrDeleted(base::asserted_cast<uint32_t>(featureIndex)); + }, collector); }); @@ -247,7 +251,9 @@ unique_ptr<coding::CompressedBitVector> RetrievePostcodeFeaturesImpl( WithSearchTrieRoot<Value>(context.m_value, [&](TrieRoot<Value> const & root) { MatchPostcodesInTrie( slice, root, - [&holder](uint32_t featureIndex) { return !holder.ModifiedOrDeleted(featureIndex); }, + [&holder](uint64_t featureIndex) { + return !holder.ModifiedOrDeleted(base::asserted_cast<uint32_t>(featureIndex)); + }, collector); }); holder.ForEachModifiedOrCreated([&](FeatureType & ft, uint64_t index) { |