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

Stephan T. Lavavej via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 7 14:00:22 PST 2016


STL_MSFT created this revision.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.

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

These tests for some guy's transparent operator functors were needlessly truncating their
double results to int. Preserving the doubleness makes compilers happier. I'm following
existing practice by adding an "// exact in binary" comment when the result isn't a whole number.
(The changes from 6 to 6.0 and so forth are stylistic, not critical.)


https://reviews.llvm.org/D27539

Files:
  test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp
  test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp
  test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp
  test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp
  test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp


Index: test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp
===================================================================
--- test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp
+++ test/std/utilities/function.objects/arithmetic.operations/plus.pass.cpp
@@ -35,7 +35,7 @@
     constexpr int foo = std::plus<int> () (3, 2);
     static_assert ( foo == 5, "" );
 
-    constexpr int bar = std::plus<> () (3.0, 2);
-    static_assert ( bar == 5, "" );
+    constexpr double bar = std::plus<> () (3.0, 2);
+    static_assert ( bar == 5.0, "" );
 #endif
 }
Index: test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp
===================================================================
--- test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp
+++ test/std/utilities/function.objects/arithmetic.operations/negate.pass.cpp
@@ -34,7 +34,7 @@
     constexpr int foo = std::negate<int> () (3);
     static_assert ( foo == -3, "" );
 
-    constexpr int bar = std::negate<> () (3.0);
-    static_assert ( bar == -3, "" );
+    constexpr double bar = std::negate<> () (3.0);
+    static_assert ( bar == -3.0, "" );
 #endif
 }
Index: test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp
===================================================================
--- test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp
+++ test/std/utilities/function.objects/arithmetic.operations/multiplies.pass.cpp
@@ -35,7 +35,7 @@
     constexpr int foo = std::multiplies<int> () (3, 2);
     static_assert ( foo == 6, "" );
 
-    constexpr int bar = std::multiplies<> () (3.0, 2);
-    static_assert ( bar == 6, "" );
+    constexpr double bar = std::multiplies<> () (3.0, 2);
+    static_assert ( bar == 6.0, "" );
 #endif
 }
Index: test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp
===================================================================
--- test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp
+++ test/std/utilities/function.objects/arithmetic.operations/minus.pass.cpp
@@ -35,7 +35,7 @@
     constexpr int foo = std::minus<int> () (3, 2);
     static_assert ( foo == 1, "" );
 
-    constexpr int bar = std::minus<> () (3.0, 2);
-    static_assert ( bar == 1, "" );
+    constexpr double bar = std::minus<> () (3.0, 2);
+    static_assert ( bar == 1.0, "" );
 #endif
 }
Index: test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp
===================================================================
--- test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp
+++ test/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp
@@ -35,7 +35,7 @@
     constexpr int foo = std::divides<int> () (3, 2);
     static_assert ( foo == 1, "" );
 
-    constexpr int bar = std::divides<> () (3.0, 2);
-    static_assert ( bar == 1, "" );
+    constexpr double bar = std::divides<> () (3.0, 2);
+    static_assert ( bar == 1.5, "" ); // exact in binary
 #endif
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27539.80653.patch
Type: text/x-patch
Size: 3070 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161207/05abfb4a/attachment.bin>


More information about the cfe-commits mailing list