[libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible loss...
authorStephan T. Lavavej <stl@exchange.microsoft.com>
Thu, 8 Dec 2016 21:37:47 +0000 (21:37 +0000)
committerStephan T. Lavavej <stl@exchange.microsoft.com>
Thu, 8 Dec 2016 21:37:47 +0000 (21:37 +0000)
Given `std::basic_streambuf<CharT>::int_type __c`, `std::basic_string<CharT> str_`,
and having checked `__c != std::basic_streambuf<CharT>::traits_type::eof()` (substituting typedefs
for clarity), the line `str_.push_back(__c);` is safe according to humans, but truncates according
to compilers. `str_.push_back(static_cast<CharT>(__c));` avoids that problem.

Fixes D27538.

llvm-svn: 289105

31 files changed:
libcxx/test/std/input.output/iostream.format/ext.manip/put_time.pass.cpp
libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf.pass.cpp
libcxx/test/std/input.output/iostream.format/input.streams/istream.unformatted/get_streambuf_chart.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/bool.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/double.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/float.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/int.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long_double.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/long_long.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/pointer.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/short.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_int.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_long.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_long_long.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/unsigned_short.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/char_pointer.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/signed_char.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/signed_char_pointer.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/unsigned_char.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.character/unsigned_char_pointer.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/basic_ios.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/ios_base.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/ostream.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/streambuf.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.manip/endl.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.manip/ends.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.rvalue/CharT_pointer.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.unformatted/put.pass.cpp
libcxx/test/std/input.output/iostream.format/output.streams/ostream.unformatted/write.pass.cpp

index d0326c5..d12b91c 100644 (file)
@@ -40,7 +40,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 1b614d3..e732729 100644 (file)
@@ -43,7 +43,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index b4e5efc..292cf7c 100644 (file)
@@ -44,7 +44,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index b7a1828..fe038a7 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index a750b74..197e460 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index c2b8375..d31da5a 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 26e6147..1b33280 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 4eb0c17..7cf4609 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 3fc2d07..dba3f8a 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 9ccfed3..1174a09 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 122bb83..f658939 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index f5c84f6..3b8182c 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index bc74e6b..61057f7 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 6b3fd5b..4558993 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index af2911e..1727b36 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 5a224b6..a42cd56 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 3e89fff..91ee08c 100644 (file)
@@ -40,7 +40,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 065a340..1eb48d3 100644 (file)
@@ -40,7 +40,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index b590ace..d57d0e7 100644 (file)
@@ -40,7 +40,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 96239ad..e51e881 100644 (file)
@@ -40,7 +40,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 2be77a3..9956f3b 100644 (file)
@@ -40,7 +40,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 190b735..d87e733 100644 (file)
@@ -40,7 +40,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index f57ad09..ef7e292 100644 (file)
@@ -40,7 +40,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 4ecd0cd..933e01c 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index f768282..5c0604b 100644 (file)
@@ -40,7 +40,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 5209494..a26450a 100644 (file)
@@ -46,7 +46,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 1a3a80a..72df608 100644 (file)
@@ -42,7 +42,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 8e39bb4..dcded34 100644 (file)
@@ -40,7 +40,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 34be3db..8be0b51 100644 (file)
@@ -43,7 +43,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 19a98c2..0958f83 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));
index 2bf0402..0d6eb3f 100644 (file)
@@ -39,7 +39,7 @@ protected:
             if (__c != base::traits_type::eof())
             {
                 int n = static_cast<int>(str_.size());
-                str_.push_back(__c);
+                str_.push_back(static_cast<CharT>(__c));
                 str_.resize(str_.capacity());
                 base::setp(const_cast<CharT*>(str_.data()),
                            const_cast<CharT*>(str_.data() + str_.size()));