From 09b4000c7c5b359ec62b5d621daf6ab95233ce10 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 24 May 2019 16:39:35 +0100 Subject: [PATCH] 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". From-SVN: r271606 --- libstdc++-v3/ChangeLog | 4 ++++ libstdc++-v3/include/std/numeric | 2 +- libstdc++-v3/testsuite/26_numerics/midpoint/pointer.cc | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0a83bd3252c..ad97108fdb0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,9 @@ 2019-05-24 Jonathan Wakely + * 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. 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 enable_if_t<__and_v, bool_constant>, _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 @@ // . // { dg-options "-std=gnu++2a" } -// { dg-do compile { target c++2a } } +// { dg-do run { target c++2a } } #include #include -- 2.30.2