This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] [test] Fix size_t-to-int truncation warnings in syserr.hash.
ClosedPublic

Authored by STL_MSFT on Dec 12 2016, 4:08 PM.

Details

Summary

[libcxx] [test] Fix size_t-to-int truncation warnings in syserr.hash.

After r289363, these tests were triggering MSVC x64 warning C4267
"conversion from 'size_t' to 'int', possible loss of data" by taking 0, 2, and 10
as std::size_t, then constructing error_code(int, const error_category&) or
error_condition(int, const error_category&) from that (N4618 19.5.3.2
[syserr.errcode.constructors]/3, 19.5.4.2 [syserr.errcondition.constructors]/3).

The fix is simple: take these ints as int, pass them to the int-taking
constructor, and perform a value-preserving static_cast<std::size_t>
when comparing them to std::size_t result.

Diff Detail

Event Timeline

STL_MSFT updated this revision to Diff 81158.Dec 12 2016, 4:08 PM
STL_MSFT retitled this revision from to [libcxx] [test] Fix a size_t-to-int truncation warning in error_code.pass.cpp..
STL_MSFT updated this object.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.
STL_MSFT updated this revision to Diff 81160.Dec 12 2016, 4:35 PM
STL_MSFT retitled this revision from [libcxx] [test] Fix a size_t-to-int truncation warning in error_code.pass.cpp. to [libcxx] [test] Fix size_t-to-int truncation warnings in syserr.hash..
STL_MSFT updated this object.
STL_MSFT edited edge metadata.

This regressed after r289363, adding that to the notes. Also, the error_condition test was equally affected, which I initially missed because we haven't implemented LWG 2686 "Why is std::hash specialized for error_code, but not error_condition?" yet (so the test is disabled for us).

EricWF accepted this revision.Dec 12 2016, 5:54 PM
EricWF edited edge metadata.
This revision is now accepted and ready to land.Dec 12 2016, 5:54 PM
STL_MSFT closed this revision.Dec 12 2016, 6:06 PM