[PATCH] D27777: [libcxx] [test] Fix MSVC x64 truncation warnings with 32-bit allocator size_type/difference_type.

Stephan T. Lavavej via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 14 14:14:28 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 truncation warnings with 32-bit allocator size_type/difference_type.

test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_container_alloc.pass.cpp
test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_container_alloc.pass.cpp
Iterate with C::size_type because that's what operator[] takes.

test/std/containers/sequences/vector/contiguous.pass.cpp
test/std/strings/basic.string/string.require/contiguous.pass.cpp
Add static_cast<typename C::difference_type> because that's what the iterator's operator+ takes.


https://reviews.llvm.org/D27777

Files:
  test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_container_alloc.pass.cpp
  test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_container_alloc.pass.cpp
  test/std/containers/sequences/vector/contiguous.pass.cpp
  test/std/strings/basic.string/string.require/contiguous.pass.cpp


Index: test/std/strings/basic.string/string.require/contiguous.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.require/contiguous.pass.cpp
+++ test/std/strings/basic.string/string.require/contiguous.pass.cpp
@@ -22,7 +22,7 @@
 void test_contiguous ( const C &c )
 {
     for ( size_t i = 0; i < c.size(); ++i )
-        assert ( *(c.begin() + i) == *(std::addressof(*c.begin()) + i));
+        assert ( *(c.begin() + static_cast<typename C::difference_type>(i)) == *(std::addressof(*c.begin()) + i));
 }
 
 int main()
Index: test/std/containers/sequences/vector/contiguous.pass.cpp
===================================================================
--- test/std/containers/sequences/vector/contiguous.pass.cpp
+++ test/std/containers/sequences/vector/contiguous.pass.cpp
@@ -21,7 +21,7 @@
 void test_contiguous ( const C &c )
 {
     for ( size_t i = 0; i < c.size(); ++i )
-        assert ( *(c.begin() + i) == *(std::addressof(*c.begin()) + i));
+        assert ( *(c.begin() + static_cast<typename C::difference_type>(i)) == *(std::addressof(*c.begin()) + i));
 }
 
 int main()
Index: test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_container_alloc.pass.cpp
===================================================================
--- test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_container_alloc.pass.cpp
+++ test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_container_alloc.pass.cpp
@@ -50,7 +50,7 @@
     test q(d, test_allocator<int>(4));
     assert(q.get_allocator() == test_allocator<int>(4));
     assert(q.size() == 5);
-    for (std::size_t i = 0; i < d.size(); ++i)
+    for (C::size_type i = 0; i < d.size(); ++i)
     {
         assert(q.top() == d[d.size() - i - 1]);
         q.pop();
Index: test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_container_alloc.pass.cpp
===================================================================
--- test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_container_alloc.pass.cpp
+++ test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_container_alloc.pass.cpp
@@ -50,7 +50,7 @@
     test q(d, test_allocator<int>(4));
     assert(q.get_allocator() == test_allocator<int>(4));
     assert(q.size() == 5);
-    for (std::size_t i = 0; i < d.size(); ++i)
+    for (C::size_type i = 0; i < d.size(); ++i)
     {
         assert(q.front() == d[i]);
         q.pop();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27777.81470.patch
Type: text/x-patch
Size: 2487 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161214/66916dfe/attachment.bin>


More information about the cfe-commits mailing list