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 4/4. Change a few allocators' size_type/difference_type from unsigned/int to std::size_t/std::ptrdiff_t. This avoids truncation warnings on x64 when unsigned/int are 32-bit but std::size_t/std::ptrdiff_t are 64-bit. https://reviews.llvm.org/D27270 Files: test/std/utilities/allocator.adaptor/types.pass.cpp test/support/allocators.h test/support/test_allocator.h Index: test/support/test_allocator.h =================================================================== --- test/support/test_allocator.h +++ test/support/test_allocator.h @@ -51,8 +51,8 @@ template <class U> friend class test_allocator; public: - typedef unsigned size_type; - typedef int difference_type; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; typedef T value_type; typedef value_type* pointer; typedef const value_type* const_pointer; @@ -112,8 +112,8 @@ template <class U> friend class non_default_test_allocator; public: - typedef unsigned size_type; - typedef int difference_type; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; typedef T value_type; typedef value_type* pointer; typedef const value_type* const_pointer; @@ -173,8 +173,8 @@ template <class U> friend class test_allocator; public: - typedef unsigned size_type; - typedef int difference_type; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; typedef void value_type; typedef value_type* pointer; typedef const value_type* const_pointer; Index: test/support/allocators.h =================================================================== --- test/support/allocators.h +++ test/support/allocators.h @@ -12,6 +12,7 @@ #include <type_traits> #include <utility> +#include <cstddef> #include "test_macros.h" @@ -85,8 +86,8 @@ typedef T value_type; - typedef unsigned size_type; - typedef int difference_type; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; typedef std::true_type propagate_on_container_move_assignment; Index: test/std/utilities/allocator.adaptor/types.pass.cpp =================================================================== --- test/std/utilities/allocator.adaptor/types.pass.cpp +++ test/std/utilities/allocator.adaptor/types.pass.cpp @@ -27,6 +27,7 @@ #include <scoped_allocator> #include <type_traits> +#include <cstddef> #include "allocators.h" @@ -76,11 +77,11 @@ static_assert((std::is_same< std::scoped_allocator_adaptor<A2<int>, A1<int>>::size_type, - unsigned>::value), ""); + std::size_t>::value), ""); static_assert((std::is_same< std::scoped_allocator_adaptor<A2<int>, A1<int>>::difference_type, - int>::value), ""); + std::ptrdiff_t>::value), ""); static_assert((std::is_same< std::scoped_allocator_adaptor<A2<int>, A1<int>>::pointer,
Index: test/support/test_allocator.h =================================================================== --- test/support/test_allocator.h +++ test/support/test_allocator.h @@ -51,8 +51,8 @@ template <class U> friend class test_allocator; public: - typedef unsigned size_type; - typedef int difference_type; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; typedef T value_type; typedef value_type* pointer; typedef const value_type* const_pointer; @@ -112,8 +112,8 @@ template <class U> friend class non_default_test_allocator; public: - typedef unsigned size_type; - typedef int difference_type; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; typedef T value_type; typedef value_type* pointer; typedef const value_type* const_pointer; @@ -173,8 +173,8 @@ template <class U> friend class test_allocator; public: - typedef unsigned size_type; - typedef int difference_type; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; typedef void value_type; typedef value_type* pointer; typedef const value_type* const_pointer; Index: test/support/allocators.h =================================================================== --- test/support/allocators.h +++ test/support/allocators.h @@ -12,6 +12,7 @@ #include <type_traits> #include <utility> +#include <cstddef> #include "test_macros.h" @@ -85,8 +86,8 @@ typedef T value_type; - typedef unsigned size_type; - typedef int difference_type; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; typedef std::true_type propagate_on_container_move_assignment; Index: test/std/utilities/allocator.adaptor/types.pass.cpp =================================================================== --- test/std/utilities/allocator.adaptor/types.pass.cpp +++ test/std/utilities/allocator.adaptor/types.pass.cpp @@ -27,6 +27,7 @@ #include <scoped_allocator> #include <type_traits> +#include <cstddef> #include "allocators.h" @@ -76,11 +77,11 @@ static_assert((std::is_same< std::scoped_allocator_adaptor<A2<int>, A1<int>>::size_type, - unsigned>::value), ""); + std::size_t>::value), ""); static_assert((std::is_same< std::scoped_allocator_adaptor<A2<int>, A1<int>>::difference_type, - int>::value), ""); + std::ptrdiff_t>::value), ""); static_assert((std::is_same< std::scoped_allocator_adaptor<A2<int>, A1<int>>::pointer,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits