[libcxx] r329973 - [libcxx] [test] Avoid MSVC truncation warnings.

Stephan T. Lavavej via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 12 16:56:07 PDT 2018


Author: stl_msft
Date: Thu Apr 12 16:56:07 2018
New Revision: 329973

URL: http://llvm.org/viewvc/llvm-project?rev=329973&view=rev
Log:
[libcxx] [test] Avoid MSVC truncation warnings.

MSVC emits "warning C4244: 'initializing': conversion from 'int'
to 'short', possible loss of data" when it sees pair<Whatever, short>
constructed from (whatever, 4), because int is being truncated to
short within pair's constructor. (The compiler doesn't take into
account the fact that 4 is a literal at the callsite; it generates
this warning when the constructor is instantiated, because it might
be called with a runtime-valued int that would actually truncate.)

Instead of static_cast<short>, we can simply change short to int
in these tests, without affecting the pair operations that they're
trying to test: move assignment, convert copy construction, and
convert move construction.

Fixes D45016.

Modified:
    libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp
    libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp
    libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp

Modified: libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp?rev=329973&r1=329972&r2=329973&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/assign_rv_pair.pass.cpp Thu Apr 12 16:56:07 2018
@@ -49,7 +49,7 @@ int CountAssign::moved = 0;
 int main()
 {
     {
-        typedef std::pair<std::unique_ptr<int>, short> P;
+        typedef std::pair<std::unique_ptr<int>, int> P;
         P p1(std::unique_ptr<int>(new int(3)), 4);
         P p2;
         p2 = std::move(p1);

Modified: libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp?rev=329973&r1=329972&r2=329973&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp Thu Apr 12 16:56:07 2018
@@ -57,7 +57,7 @@ struct ImplicitT {
 int main()
 {
     {
-        typedef std::pair<int, short> P1;
+        typedef std::pair<int, int> P1;
         typedef std::pair<double, long> P2;
         const P1 p1(3, 4);
         const P2 p2 = p1;
@@ -154,7 +154,7 @@ int main()
     }
 #if TEST_STD_VER > 11
     {
-        typedef std::pair<int, short> P1;
+        typedef std::pair<int, int> P1;
         typedef std::pair<double, long> P2;
         constexpr P1 p1(3, 4);
         constexpr P2 p2 = p1;

Modified: libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp?rev=329973&r1=329972&r2=329973&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/rv_pair_U_V.pass.cpp Thu Apr 12 16:56:07 2018
@@ -67,7 +67,7 @@ struct ImplicitT {
 int main()
 {
     {
-        typedef std::pair<std::unique_ptr<Derived>, short> P1;
+        typedef std::pair<std::unique_ptr<Derived>, int> P1;
         typedef std::pair<std::unique_ptr<Base>, long> P2;
         P1 p1(std::unique_ptr<Derived>(), 4);
         P2 p2 = std::move(p1);




More information about the cfe-commits mailing list