[PATCH] D32574: [libcxx] [test] Fixed possible loss of data warnings in tests on amd64

Billy Robert O'Neal III via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 8 14:43:27 PDT 2017


BillyONeal updated this revision to Diff 98214.
BillyONeal marked 4 inline comments as done.
BillyONeal edited the summary of this revision.
BillyONeal added a comment.

Instead, change the tests to pass around std::size_t instances, and explicitly
narrow when constructing the string type under test. This also allows
removal of explicit template arguments to std::min.


https://reviews.llvm.org/D32574

Files:
  test/std/strings/basic.string/string.cons/T_size_size.pass.cpp


Index: test/std/strings/basic.string/string.cons/T_size_size.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.cons/T_size_size.pass.cpp
+++ test/std/strings/basic.string/string.cons/T_size_size.pass.cpp
@@ -27,16 +27,17 @@
 
 template <class S, class SV>
 void
-test(SV sv, unsigned pos, unsigned n)
+test(SV sv, std::size_t pos, std::size_t n)
 {
     typedef typename S::traits_type T;
     typedef typename S::allocator_type A;
+    typedef typename S::size_type Size;
     if (pos <= sv.size())
     {
-        S s2(sv, pos, n);
+        S s2(sv, static_cast<Size>(pos), static_cast<Size>(n));
         LIBCPP_ASSERT(s2.__invariants());
         assert(pos <= sv.size());
-        unsigned rlen = std::min<unsigned>(sv.size() - pos, n);
+        std::size_t rlen = std::min(sv.size() - pos, n);
         assert(s2.size() == rlen);
         assert(T::compare(s2.data(), sv.data() + pos, rlen) == 0);
         assert(s2.get_allocator() == A());
@@ -47,7 +48,7 @@
     {
         try
         {
-            S s2(sv, pos, n);
+            S s2(sv, static_cast<Size>(pos), static_cast<Size>(n));
             assert(false);
         }
         catch (std::out_of_range&)
@@ -60,15 +61,16 @@
 
 template <class S, class SV>
 void
-test(SV sv, unsigned pos, unsigned n, const typename S::allocator_type& a)
+test(SV sv, std::size_t pos, std::size_t n, const typename S::allocator_type& a)
 {
     typedef typename S::traits_type T;
+    typedef typename S::size_type Size;
     if (pos <= sv.size())
     {
-        S s2(sv, pos, n, a);
+        S s2(sv, static_cast<Size>(pos), static_cast<Size>(n), a);
         LIBCPP_ASSERT(s2.__invariants());
         assert(pos <= sv.size());
-        unsigned rlen = std::min<unsigned>(sv.size() - pos, n);
+        std::size_t rlen = std::min(sv.size() - pos, n);
         assert(s2.size() == rlen);
         assert(T::compare(s2.data(), sv.data() + pos, rlen) == 0);
         assert(s2.get_allocator() == a);
@@ -79,7 +81,7 @@
     {
         try
         {
-            S s2(sv, pos, n, a);
+            S s2(sv, static_cast<Size>(pos), static_cast<Size>(n), a);
             assert(false);
         }
         catch (std::out_of_range&)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32574.98214.patch
Type: text/x-patch
Size: 2249 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170508/e10b359e/attachment-0001.bin>


More information about the cfe-commits mailing list