[PATCH] Fix std::midpoint(T*, T*) for reversed arguments
Jonathan Wakely
jwakely@redhat.com
Fri May 24 15:39:00 GMT 2019
* include/std/numeric (midpoint(T*, T*)): Fix incorrect result.
* testsuite/26_numerics/midpoint/pointer.cc: Change "compile" test
to "run".
Tested x86_64-linux, committed to trunk. I'll backport to gcc-9-branch
too.
-------------- next part --------------
commit c8993a6a75753f9be84edaa692dc36e50dc9b30f
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri May 24 14:03:51 2019 +0100
Fix std::midpoint(T*, T*) for reversed arguments
* include/std/numeric (midpoint(T*, T*)): Fix incorrect result.
* testsuite/26_numerics/midpoint/pointer.cc: Change "compile" test
to "run".
diff --git a/libstdc++-v3/include/std/numeric b/libstdc++-v3/include/std/numeric
index 4858ad1aea3..9dff247538a 100644
--- a/libstdc++-v3/include/std/numeric
+++ b/libstdc++-v3/include/std/numeric
@@ -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
diff --git a/libstdc++-v3/testsuite/26_numerics/midpoint/pointer.cc b/libstdc++-v3/testsuite/26_numerics/midpoint/pointer.cc
index bd586d28ba0..3d3aafc3ec8 100644
--- a/libstdc++-v3/testsuite/26_numerics/midpoint/pointer.cc
+++ b/libstdc++-v3/testsuite/26_numerics/midpoint/pointer.cc
@@ -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>
More information about the Libstdc++
mailing list