This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by STL_MSFT on Dec 7 2016, 1:59 PM.

Details

Summary

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

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.

Diff Detail

Event Timeline

STL_MSFT updated this revision to Diff 80652.Dec 7 2016, 1:59 PM
STL_MSFT retitled this revision from to [libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible loss of data", part 1/7..
STL_MSFT updated this object.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.
EricWF accepted this revision.Dec 7 2016, 10:58 PM
EricWF edited edge metadata.
This revision is now accepted and ready to land.Dec 7 2016, 10:58 PM
STL_MSFT closed this revision.Dec 8 2016, 1:57 PM