STL_MSFT created this revision. STL_MSFT added reviewers: EricWF, mclow.lists. STL_MSFT added a subscriber: cfe-commits.
[libcxx] [test] Fix a size_t-to-int truncation warning in error_code.pass.cpp. This test was 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&) from that (N4618 19.5.3.2 [syserr.errcode.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`. https://reviews.llvm.org/D27691 Files: test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp Index: test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp =================================================================== --- test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp +++ test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp @@ -23,16 +23,16 @@ #include "test_macros.h" void -test(std::size_t i) +test(int i) { typedef std::error_code T; typedef std::hash<T> H; static_assert((std::is_same<H::argument_type, T>::value), "" ); static_assert((std::is_same<H::result_type, std::size_t>::value), "" ); H h; T ec(i, std::system_category()); const std::size_t result = h(ec); - LIBCPP_ASSERT(result == i); + LIBCPP_ASSERT(result == static_cast<std::size_t>(i)); ((void)result); // Prevent unused warning }
Index: test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp =================================================================== --- test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp +++ test/std/diagnostics/syserr/syserr.hash/error_code.pass.cpp @@ -23,16 +23,16 @@ #include "test_macros.h" void -test(std::size_t i) +test(int i) { typedef std::error_code T; typedef std::hash<T> H; static_assert((std::is_same<H::argument_type, T>::value), "" ); static_assert((std::is_same<H::result_type, std::size_t>::value), "" ); H h; T ec(i, std::system_category()); const std::size_t result = h(ec); - LIBCPP_ASSERT(result == i); + LIBCPP_ASSERT(result == static_cast<std::size_t>(i)); ((void)result); // Prevent unused warning }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits