[PATCH] D27270: [libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' [or 'unsigned int'], possible loss of data", part 4/4.
Stephan T. Lavavej via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 30 10:05:49 PST 2016
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,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27270.79775.patch
Type: text/x-patch
Size: 3603 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161130/38f2e412/attachment-0001.bin>
More information about the cfe-commits
mailing list