This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' [or 'unsigned int'], possible loss of data", part 1/4.
ClosedPublic

Authored by STL_MSFT on Nov 30 2016, 10:02 AM.

Details

Summary

[libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' [or 'unsigned int'], possible loss of data", part 1/4.

Replace "int n = str_.size();" with "int n = static_cast<int>(str_.size());".

int is the correct type to use, because we're eventually calling
"base::pbump(n+1);" where base is std::basic_streambuf.
N4606 27.6.3.3.3 [streambuf.put.area]/4 declares: "void pbump(int n);"

Diff Detail

Event Timeline

STL_MSFT updated this revision to Diff 79772.Nov 30 2016, 10:02 AM
STL_MSFT retitled this revision from to [libcxx] [test] Fix MSVC x64 warning C4267 "conversion from 'size_t' to 'int' [or 'unsigned int'], possible loss of data", part 1/4..
STL_MSFT updated this object.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.
EricWF accepted this revision.Dec 2 2016, 11:42 PM
EricWF edited edge metadata.

LGTM.

Random thought: It would be nice for C++ to have a non_truncating_cast<T>(value) which generated an error when the conversion performs a truncation. This seems like the behavior we want for most of these changes, since the cast *shouldn't* truncate.

This revision is now accepted and ready to land.Dec 2 2016, 11:42 PM
STL_MSFT closed this revision.Dec 5 2016, 5:28 PM

Thanks, r288751.