From fc05f9e90a0a00a9450e01a662f9a8157fc7c13c Mon Sep 17 00:00:00 2001 From: Ole Erik Peistorpet Date: Sun, 2 Jun 2024 15:09:08 +0200 Subject: [PATCH] Fixed a few more Wsign-conversion warnings --- dynarray.h | 2 +- unit_test/dynarray_mutate_gtest.cpp | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/dynarray.h b/dynarray.h index f8716795..d1ee9439 100644 --- a/dynarray.h +++ b/dynarray.h @@ -27,7 +27,7 @@ is_trivially_relocatable specify_trivial_relocate(dynarray); //! Overloads generic unordered_erase(RandomAccessContainer &, Integral) (in range_algo.h) template< typename T, typename A > inline -void unordered_erase(dynarray & d, size_t index) { d.unordered_erase(d.begin() + index); } +void unordered_erase(dynarray & d, ptrdiff_t index) { d.unordered_erase(d.begin() + index); } #if OEL_MEM_BOUND_DEBUG_LVL inline namespace debug diff --git a/unit_test/dynarray_mutate_gtest.cpp b/unit_test/dynarray_mutate_gtest.cpp index 6d1bef03..ab456fb6 100644 --- a/unit_test/dynarray_mutate_gtest.cpp +++ b/unit_test/dynarray_mutate_gtest.cpp @@ -440,33 +440,34 @@ TEST_F(dynarrayTest, insertRTrivial) TEST_F(dynarrayTest, insertR) { - size_t const initSize = 2; + using oel::ssize; + constexpr ptrdiff_t initSize{2}; std::array const toInsert{TrivialRelocat{-1}, TrivialRelocat{-2}}; - for (auto nReserve : {initSize, initSize + toInsert.size()}) - for (size_t insertOffset = 0; insertOffset <= initSize; ++insertOffset) - for (unsigned countThrow = 0; countThrow <= toInsert.size(); ++countThrow) + for (auto nReserve : {initSize, initSize + ssize(toInsert)}) + for (ptrdiff_t insertOffset{}; insertOffset <= initSize; ++insertOffset) + for (int countThrow{}; countThrow <= ssize(toInsert); ++countThrow) { { - dynarray dest(oel::reserve, nReserve); + dynarray dest(oel::reserve, oel::as_unsigned(nReserve)); dest.emplace_back(1); dest.emplace_back(2); - if (countThrow < toInsert.size()) + if (countThrow < ssize(toInsert)) { #if OEL_HAS_EXCEPTIONS - TrivialRelocat::countToThrowOn = oel::as_signed(countThrow); + TrivialRelocat::countToThrowOn = countThrow; EXPECT_THROW( dest.insert_range(dest.begin() + insertOffset, toInsert), TestException ); #endif - EXPECT_TRUE(initSize <= dest.size() and dest.size() <= initSize + countThrow); + EXPECT_TRUE(initSize <= ssize(dest) and ssize(dest) <= initSize + countThrow); } else { dest.insert_range(dest.begin() + insertOffset, toInsert); - EXPECT_TRUE(dest.size() == initSize + toInsert.size()); + EXPECT_TRUE(ssize(dest) == initSize + ssize(toInsert)); } if (dest.size() > initSize) { - for (unsigned i = 0; i < countThrow; ++i) - EXPECT_TRUE( *toInsert[i] == *dest[i + insertOffset] ); + for (size_t i{}; i < oel::as_unsigned(countThrow); ++i) + EXPECT_TRUE( *toInsert[i] == *dest[i + oel::as_unsigned(insertOffset)] ); } if (insertOffset == 0) { @@ -483,7 +484,7 @@ TEST_F(dynarrayTest, insertR) EXPECT_EQ(2, *dest.back()); } } - EXPECT_EQ(TrivialRelocat::nConstructions, TrivialRelocat::nDestruct + oel::ssize(toInsert)); + EXPECT_EQ(TrivialRelocat::nConstructions, TrivialRelocat::nDestruct + ssize(toInsert)); } }