Fix std::midpoint(T*, T*) for reversed arguments
authorJonathan Wakely <jwakely@redhat.com>
Fri, 24 May 2019 15:39:35 +0000 (16:39 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 24 May 2019 15:39:35 +0000 (16:39 +0100)
* include/std/numeric (midpoint(T*, T*)): Fix incorrect result.
* testsuite/26_numerics/midpoint/pointer.cc: Change "compile" test
to "run".

From-SVN: r271606

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/numeric
libstdc++-v3/testsuite/26_numerics/midpoint/pointer.cc

index 0a83bd3252ca35cd6290212bde238d984d377505..ad97108fdb0a3122f06991a9159ab90a86efc454 100644 (file)
@@ -1,5 +1,9 @@
 2019-05-24  Jonathan Wakely  <jwakely@redhat.com>
 
+       * include/std/numeric (midpoint(T*, T*)): Fix incorrect result.
+       * testsuite/26_numerics/midpoint/pointer.cc: Change "compile" test
+       to "run".
+
        * testsuite/20_util/shared_ptr/cons/alias-rval.cc: Fix test.
        * testsuite/20_util/shared_ptr/cons/alias.cc: Remove unused function.
 
index 4858ad1aea3a2af25df72b62d0bcb9a666bb50aa..9dff247538ac6c324610ca905d9992d35c412298 100644 (file)
@@ -195,7 +195,7 @@ template<typename _Tp>
     enable_if_t<__and_v<is_object<_Tp>, bool_constant<sizeof(_Tp) != 0>>, _Tp*>
     midpoint(_Tp* __a, _Tp* __b) noexcept
     {
-      return __a > __b ? __b + (__a - __b) / 2 : __a + (__b - __a) / 2;
+      return __a  + (__b - __a) / 2;
     }
 #endif // C++20
 
index bd586d28ba011c890d34648399690bac9dfdadd2..3d3aafc3ec868af9617ba77990de922711ada84f 100644 (file)
@@ -16,7 +16,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-options "-std=gnu++2a" }
-// { dg-do compile { target c++2a } }
+// { dg-do run { target c++2a } }
 
 #include <numeric>
 #include <climits>