[PATCH] D27268: [libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' [or 'unsigned int'], possible loss of data", part 2/4.
STL_MSFT closed this revision. STL_MSFT added a comment. Thanks, r288752. https://reviews.llvm.org/D27268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27268: [libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' [or 'unsigned int'], possible loss of data", part 2/4.
STL_MSFT updated this revision to Diff 80348. STL_MSFT added a comment. Changed data members to size_t as requested (also changed parameters for consistency). https://reviews.llvm.org/D27268 Files: test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp test/support/archetypes.hpp test/support/count_new.hpp Index: test/support/count_new.hpp === --- test/support/count_new.hpp +++ test/support/count_new.hpp @@ -59,12 +59,12 @@ int outstanding_new; int new_called; int delete_called; -int last_new_size; +std::size_t last_new_size; int outstanding_array_new; int new_array_called; int delete_array_called; -int last_new_array_size; +std::size_t last_new_array_size; public: void newCalled(std::size_t s) @@ -174,12 +174,12 @@ return disable_checking || n != delete_called; } -bool checkLastNewSizeEq(int n) const +bool checkLastNewSizeEq(std::size_t n) const { return disable_checking || n == last_new_size; } -bool checkLastNewSizeNotEq(int n) const +bool checkLastNewSizeNotEq(std::size_t n) const { return disable_checking || n != last_new_size; } @@ -214,12 +214,12 @@ return disable_checking || n != delete_array_called; } -bool checkLastNewArraySizeEq(int n) const +bool checkLastNewArraySizeEq(std::size_t n) const { return disable_checking || n == last_new_array_size; } -bool checkLastNewArraySizeNotEq(int n) const +bool checkLastNewArraySizeNotEq(std::size_t n) const { return disable_checking || n != last_new_array_size; } @@ -304,10 +304,10 @@ void requireExactly(std::size_t N) { m_req_alloc = N; m_exactly = true; } ~RequireAllocationGuard() { -assert(globalMemCounter.checkOutstandingNewEq(m_outstanding_new_on_init)); +assert(globalMemCounter.checkOutstandingNewEq(static_cast(m_outstanding_new_on_init))); std::size_t Expect = m_new_count_on_init + m_req_alloc; -assert(globalMemCounter.checkNewCalledEq(Expect) || - (!m_exactly && globalMemCounter.checkNewCalledGreaterThan(Expect))); +assert(globalMemCounter.checkNewCalledEq(static_cast(Expect)) || + (!m_exactly && globalMemCounter.checkNewCalledGreaterThan(static_cast(Expect; } private: Index: test/support/archetypes.hpp === --- test/support/archetypes.hpp +++ test/support/archetypes.hpp @@ -69,11 +69,11 @@ } template ::type = true> explicit TestBase(std::initializer_list& il, int = 0) noexcept - : value(il.size()) { + : value(static_cast(il.size())) { ++alive; ++constructed; ++value_constructed; } template ::type = true> -explicit TestBase(std::initializer_list& il, int = 0) noexcept : value(il.size()) { +explicit TestBase(std::initializer_list& il, int = 0) noexcept : value(static_cast(il.size())) { ++alive; ++constructed; ++value_constructed; } TestBase& operator=(int xvalue) noexcept { @@ -135,9 +135,9 @@ template ::type = true> constexpr ValueBase(int, int y) : value(y) {} template ::type = true> -explicit constexpr ValueBase(std::initializer_list& il, int = 0) : value(il.size()) {} +explicit constexpr ValueBase(std::initializer_list& il, int = 0) : value(static_cast(il.size())) {} template ::type = true> -constexpr ValueBase(std::initializer_list& il, int = 0) : value(il.size()) {} +constexpr ValueBase(std::initializer_list& il, int = 0) : value(static_cast(il.size())) {} TEST_CONSTEXPR_CXX14 ValueBase& operator=(int xvalue) noexcept { value = xvalue; return *this; @@ -193,9 +193,9 @@ template ::type = true> constexpr TrivialValueBase(int, int y) : value(y) {} template ::type = true> -explicit constexpr TrivialValueBase(std::initializer_list& il, int = 0) : value(il.size()) {} +explicit constexpr TrivialValueBase(std::initializer_list& il, int = 0) : value(static_cast(il.size())) {} template ::type = true> -constexpr TrivialValueBase(std::initializer_list& il, int = 0) : value(il.size()) {}; +constexpr TrivialValueBase(std::initializer_list& il, int = 0) : value(static_cast(il.size())) {} int value; protected: constexpr TrivialValueBase() noexcept : value(0) {} Index: test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp === --- test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp +++ test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp @@ -23,9 +23,9 @@ struct TestT { int x; int size; - constexpr TestT(std::initializer_list il) :
[PATCH] D27268: [libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' [or 'unsigned int'], possible loss of data", part 2/4.
EricWF accepted this revision. EricWF added a comment. This revision is now accepted and ready to land. LGTM nix inline comments. Please fix `MemCounter` to use `size_t` instead. Comment at: test/support/count_new.hpp:62 int delete_called; int last_new_size; These should be changed to `size_t` instead. https://reviews.llvm.org/D27268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D27268: [libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' [or 'unsigned int'], possible loss of data", part 2/4.
STL_MSFT created this revision. STL_MSFT added reviewers: EricWF, mclow.lists. STL_MSFT added a subscriber: cfe-commits. [libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' [or 'unsigned int'], possible loss of data", part 2/4. Use static_cast when storing size_t in int (or passing size_t to int). Also, remove a spurious semicolon in test/support/archetypes.hpp. https://reviews.llvm.org/D27268 Files: test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp test/support/archetypes.hpp test/support/count_new.hpp Index: test/support/count_new.hpp === --- test/support/count_new.hpp +++ test/support/count_new.hpp @@ -79,7 +79,7 @@ } ++new_called; ++outstanding_new; -last_new_size = s; +last_new_size = static_cast(s); } void deleteCalled(void * p) @@ -101,7 +101,7 @@ } ++outstanding_array_new; ++new_array_called; -last_new_array_size = s; +last_new_array_size = static_cast(s); } void deleteArrayCalled(void * p) @@ -304,10 +304,10 @@ void requireExactly(std::size_t N) { m_req_alloc = N; m_exactly = true; } ~RequireAllocationGuard() { - assert(globalMemCounter.checkOutstandingNewEq(m_outstanding_new_on_init)); + assert(globalMemCounter.checkOutstandingNewEq(static_cast(m_outstanding_new_on_init))); std::size_t Expect = m_new_count_on_init + m_req_alloc; -assert(globalMemCounter.checkNewCalledEq(Expect) || - (!m_exactly && globalMemCounter.checkNewCalledGreaterThan(Expect))); +assert(globalMemCounter.checkNewCalledEq(static_cast(Expect)) || + (!m_exactly && globalMemCounter.checkNewCalledGreaterThan(static_cast(Expect; } private: Index: test/support/archetypes.hpp === --- test/support/archetypes.hpp +++ test/support/archetypes.hpp @@ -69,11 +69,11 @@ } template ::type = true> explicit TestBase(std::initializer_list& il, int = 0) noexcept - : value(il.size()) { + : value(static_cast(il.size())) { ++alive; ++constructed; ++value_constructed; } template ::type = true> -explicit TestBase(std::initializer_list& il, int = 0) noexcept : value(il.size()) { +explicit TestBase(std::initializer_list& il, int = 0) noexcept : value(static_cast(il.size())) { ++alive; ++constructed; ++value_constructed; } TestBase& operator=(int xvalue) noexcept { @@ -135,9 +135,9 @@ template ::type = true> constexpr ValueBase(int, int y) : value(y) {} template ::type = true> -explicit constexpr ValueBase(std::initializer_list& il, int = 0) : value(il.size()) {} +explicit constexpr ValueBase(std::initializer_list& il, int = 0) : value(static_cast(il.size())) {} template ::type = true> -constexpr ValueBase(std::initializer_list& il, int = 0) : value(il.size()) {} +constexpr ValueBase(std::initializer_list& il, int = 0) : value(static_cast(il.size())) {} TEST_CONSTEXPR_CXX14 ValueBase& operator=(int xvalue) noexcept { value = xvalue; return *this; @@ -193,9 +193,9 @@ template ::type = true> constexpr TrivialValueBase(int, int y) : value(y) {} template ::type = true> -explicit constexpr TrivialValueBase(std::initializer_list& il, int = 0) : value(il.size()) {} +explicit constexpr TrivialValueBase(std::initializer_list& il, int = 0) : value(static_cast(il.size())) {} template ::type = true> -constexpr TrivialValueBase(std::initializer_list& il, int = 0) : value(il.size()) {}; +constexpr TrivialValueBase(std::initializer_list& il, int = 0) : value(static_cast(il.size())) {} int value; protected: constexpr TrivialValueBase() noexcept : value(0) {} Index: test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp === --- test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp +++ test/std/utilities/optional/optional.specalg/make_optional_explicit_initializer_list.pass.cpp @@ -23,9 +23,9 @@ struct TestT { int x; int size; - constexpr TestT(std::initializer_list il) : x(*il.begin()), size(il.size()) {} + constexpr TestT(std::initializer_list il) : x(*il.begin()), size(static_cast(il.size())) {} constexpr TestT(std::initializer_list il, const int*) - : x(*il.begin()), size(il.size()) {} + : x(*il.begin()), size(static_cast(il.size())) {} }; int main() Index: test/support/count_new.hpp === --- test/support/count_new.hpp +++ test/support/count_new.hpp @@ -79,7 +79,7 @@ } ++new_called; ++outstanding_new; -