[libcxx] r289110 - [libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible loss of data", part 6/7.

Stephan T. Lavavej via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 8 13:38:44 PST 2016


Author: stl_msft
Date: Thu Dec  8 15:38:44 2016
New Revision: 289110

URL: http://llvm.org/viewvc/llvm-project?rev=289110&view=rev
Log:
[libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible loss of data", part 6/7.

test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp
(Affects 64-bit architectures.) Include <cstddef> so we can take/return std::ptrdiff_t
(instead of int) in random_shuffle()'s RNG. (C++14 D.12 [depr.alg.random.shuffle]/2 says that
difference_type is used, and we're shuffling a plain array.)

test/std/algorithms/alg.sorting/alg.sort/sort/sort.pass.cpp
test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp
(Affects 64-bit architectures.) Include <iterator> because we're already using iterator_traits.
Then, store the result of subtracting two RanIts as difference_type instead of long
(which truncates on LLP64 architectures like MSVC x64).

test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp
test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp
(Affects 64-bit architectures.) Include <cstddef> so we can store the result of
subtracting two pointers as std::ptrdiff_t (instead of int).

test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore_0xff.pass.cpp
(Affects 32-bit architectures.) Sometimes, size_t is too small. That's the case here,
where tellg() returns pos_type (N4606 27.7.2.3 [istream.unformatted]/39). Implementations can
have 64-bit pos_type (to handle large files) even when they have 32-bit size_t.

Fixes D27543.

Modified:
    libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp
    libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/sort/sort.pass.cpp
    libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp
    libcxx/trunk/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp
    libcxx/trunk/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp
    libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore_0xff.pass.cpp

Modified: libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp?rev=289110&r1=289109&r2=289110&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp Thu Dec  8 15:38:44 2016
@@ -17,12 +17,13 @@
 
 #include <algorithm>
 #include <cassert>
+#include <cstddef>
 
 #include "test_macros.h"
 
 struct gen
 {
-    int operator()(int n)
+    std::ptrdiff_t operator()(std::ptrdiff_t n)
     {
         return n-1;
     }

Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/sort/sort.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/sort/sort.pass.cpp?rev=289110&r1=289109&r2=289110&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/sort/sort.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/sort/sort.pass.cpp Thu Dec  8 15:38:44 2016
@@ -16,6 +16,7 @@
 //   sort(Iter first, Iter last);
 
 #include <algorithm>
+#include <iterator>
 #include <cassert>
 
 template <class RI>
@@ -23,9 +24,11 @@ void
 test_sort_helper(RI f, RI l)
 {
     typedef typename std::iterator_traits<RI>::value_type value_type;
+    typedef typename std::iterator_traits<RI>::difference_type difference_type;
+
     if (f != l)
     {
-        long len = l - f;
+        difference_type len = l - f;
         value_type* save(new value_type[len]);
         do
         {

Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp?rev=289110&r1=289109&r2=289110&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.sort/stable.sort/stable_sort.pass.cpp Thu Dec  8 15:38:44 2016
@@ -16,6 +16,7 @@
 //   stable_sort(Iter first, Iter last);
 
 #include <algorithm>
+#include <iterator>
 #include <cassert>
 
 template <class RI>
@@ -23,9 +24,11 @@ void
 test_sort_helper(RI f, RI l)
 {
     typedef typename std::iterator_traits<RI>::value_type value_type;
+    typedef typename std::iterator_traits<RI>::difference_type difference_type;
+
     if (f != l)
     {
-        long len = l - f;
+        difference_type len = l - f;
         value_type* save(new value_type[len]);
         do
         {

Modified: libcxx/trunk/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp?rev=289110&r1=289109&r2=289110&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp Thu Dec  8 15:38:44 2016
@@ -14,14 +14,15 @@
 #include <forward_list>
 #include <cassert>
 #include <iterator>
+#include <cstddef>
 
 #include "min_allocator.h"
 
 typedef int T;
 const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7};
 const T t2[] = {10, 11, 12, 13, 14, 15};
-const int size_t1 = std::end(t1) - std::begin(t1);
-const int size_t2 = std::end(t2) - std::begin(t2);
+const std::ptrdiff_t size_t1 = std::end(t1) - std::begin(t1);
+const std::ptrdiff_t size_t2 = std::end(t2) - std::begin(t2);
 
 template <class C>
 void

Modified: libcxx/trunk/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp?rev=289110&r1=289109&r2=289110&view=diff
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp Thu Dec  8 15:38:44 2016
@@ -14,6 +14,7 @@
 #include <forward_list>
 #include <cassert>
 #include <iterator>
+#include <cstddef>
 
 #include "test_macros.h"
 #include "min_allocator.h"
@@ -21,8 +22,8 @@
 typedef int T;
 const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7};
 const T t2[] = {10, 11, 12};
-const int size_t1 = std::end(t1) - std::begin(t1);
-const int size_t2 = std::end(t2) - std::begin(t2);
+const std::ptrdiff_t size_t1 = std::end(t1) - std::begin(t1);
+const std::ptrdiff_t size_t2 = std::end(t2) - std::begin(t2);
 
 template <class C>
 void

Modified: libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore_0xff.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore_0xff.pass.cpp?rev=289110&r1=289109&r2=289110&view=diff
==============================================================================
--- libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore_0xff.pass.cpp (original)
+++ libcxx/trunk/test/std/input.output/iostream.format/input.streams/istream.unformatted/ignore_0xff.pass.cpp Thu Dec  8 15:38:44 2016
@@ -27,8 +27,8 @@ int main()
 
     std::istringstream is(s);
     const unsigned int ignoreLen=10;
-    size_t a=is.tellg();
+    std::istringstream::pos_type a=is.tellg();
     is.ignore(ignoreLen);
-    size_t b=is.tellg();
+    std::istringstream::pos_type b=is.tellg();
     assert((b-a)==ignoreLen);
 }




More information about the cfe-commits mailing list