[libcxx] [test] Fix MSVC warning C4244 "conversion from 'X' to 'Y', possible loss...
authorStephan T. Lavavej <stl@exchange.microsoft.com>
Thu, 8 Dec 2016 21:38:01 +0000 (21:38 +0000)
committerStephan T. Lavavej <stl@exchange.microsoft.com>
Thu, 8 Dec 2016 21:38:01 +0000 (21:38 +0000)
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.)

Fixes D27539.

llvm-svn: 289106

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

index d9471b5..7419b70 100644 (file)
@@ -35,7 +35,7 @@ int main()
     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
 }
index e8f5f5f..25df69d 100644 (file)
@@ -35,7 +35,7 @@ int main()
     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 dd41f93..2b35482 100644 (file)
@@ -35,7 +35,7 @@ int main()
     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 95a688f..1988940 100644 (file)
@@ -34,7 +34,7 @@ int main()
     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 ad2b14e..b56d3ef 100644 (file)
@@ -35,7 +35,7 @@ int main()
     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
 }