public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix std::midpoint(T*, T*) for reversed arguments
@ 2019-05-24 15:39 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2019-05-24 15:39 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 223 bytes --]

	* 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.



[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1368 bytes --]

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>

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-05-24 15:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-24 15:39 [PATCH] Fix std::midpoint(T*, T*) for reversed arguments Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).