Tested on Linux-x64.

The tests apparently would never fail unless the arrays are global
and the pointer arithmetic local. However, these tests should
ensure that the results are the same regardless of optimizations,
and these test fail with the current compiler unless the specializations
are present.

2017-01-22  Ville Voutilainen  <ville.voutilai...@gmail.com>

    PR libstdc++/78420
    * include/bits/stl_function.h (<cstdint>): New include in C++11 mode
    and above.
    (greater<_Tp*>): New specialization in C++11 mode and above.
    (less<_Tp*>): Likewise.
    (greater_equal<_Tp*>): Likewise.
    (less_equal<_Tp*>): Likewise.
    * testsuite/20_util/function_objects/pointer_comparison.cc: New.
    * testsuite/20_util/function_objects/pointer_comparison.inl: Likewise.
    * testsuite/20_util/function_objects/pointer_comparison_opt.cc:
    Likewise.
diff --git a/libstdc++-v3/include/bits/stl_function.h 
b/libstdc++-v3/include/bits/stl_function.h
index 4fbcdb9..5b36b8b 100644
--- a/libstdc++-v3/include/bits/stl_function.h
+++ b/libstdc++-v3/include/bits/stl_function.h
@@ -60,6 +60,10 @@
 #include <bits/move.h>
 #endif
 
+#if __cplusplus >= 201103L
+#include <cstdint>
+#endif
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -386,6 +390,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { return __x < __y; }
     };
 
+#if __cplusplus >= 201103L
+  template<typename _Tp>
+    struct greater<_Tp*> : public binary_function<_Tp*, _Tp*, bool>
+    {
+      _GLIBCXX14_CONSTEXPR
+      bool
+      operator()(_Tp* __x, _Tp* __y) const
+      { return uintptr_t(__x) > uintptr_t(__y); }
+    };
+
+  template<typename _Tp>
+    struct less<_Tp*> : public binary_function<_Tp*, _Tp*, bool>
+    {
+      _GLIBCXX14_CONSTEXPR
+      bool
+      operator()(_Tp* __x, _Tp* __y) const
+      { return uintptr_t(__x) < uintptr_t(__y); }
+    };
+#endif
+
   /// One of the @link comparison_functors comparison functors@endlink.
   template<typename _Tp>
     struct greater_equal : public binary_function<_Tp, _Tp, bool>
@@ -406,6 +430,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { return __x <= __y; }
     };
 
+#if __cplusplus >= 201103L
+  template<typename _Tp>
+    struct greater_equal<_Tp*> : public binary_function<_Tp*, _Tp*, bool>
+    {
+      _GLIBCXX14_CONSTEXPR
+      bool
+      operator()(_Tp* __x, _Tp* __y) const
+      { return uintptr_t(__x) >= uintptr_t(__y); }
+    };
+
+  template<typename _Tp>
+    struct less_equal<_Tp*> : public binary_function<_Tp*, _Tp*, bool>
+    {
+      _GLIBCXX14_CONSTEXPR
+      bool
+      operator()(_Tp* __x, _Tp* __y) const
+      { return uintptr_t(__x) <= uintptr_t(__y); }
+    };
+#endif
+
 #if __cplusplus > 201103L
   /// One of the @link comparison_functors comparison functors@endlink.
   template<>
diff --git 
a/libstdc++-v3/testsuite/20_util/function_objects/pointer_comparison.cc 
b/libstdc++-v3/testsuite/20_util/function_objects/pointer_comparison.cc
new file mode 100644
index 0000000..5ab28dc
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/function_objects/pointer_comparison.cc
@@ -0,0 +1,26 @@
+// { dg-options "-O0" }
+// { dg-do run { target c++11 } }
+
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 20.9.5-20.9.9
+
+#include <functional>
+#include <testsuite_hooks.h>
+
+#include "pointer_comparison.inl"
diff --git 
a/libstdc++-v3/testsuite/20_util/function_objects/pointer_comparison.inl 
b/libstdc++-v3/testsuite/20_util/function_objects/pointer_comparison.inl
new file mode 100644
index 0000000..532cc38
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/function_objects/pointer_comparison.inl
@@ -0,0 +1,47 @@
+int b[8];
+int a[8];
+
+
+void test01()
+{
+  auto p = a + 8;
+  std::less<int*> lt;
+  VERIFY((lt(p, b) && !lt(b, p) && !(!lt(p, b) && !lt(b, p)))
+        || (!lt(p, b) && lt(b, p) && !(!lt(p, b) && !lt(b, p)))
+        || (!lt(p, b) && !lt(b, p) && (!lt(p, b) && !lt(b, p))));
+}
+
+void test02()
+{
+  auto p = a + 8;
+  std::greater<int*> gt;
+  VERIFY((gt(p, b) && !gt(b, p) && !(!gt(p, b) && !gt(b, p)))
+        || (!gt(p, b) && gt(b, p) && !(!gt(p, b) && !gt(b, p)))
+        || (!gt(p, b) && !gt(b, p) && (!gt(p, b) && !gt(b, p))));
+}
+
+void test03()
+{
+  auto p = a + 8;
+  std::less_equal<int*> le;
+  VERIFY((le(p, b) && !le(b, p) && !(le(p, b) && le(b, p)))
+        || (!le(p, b) && le(b, p) && !(le(p, b) && le(b, p)))
+        || (le(p, b) && le(b, p) && !(!le(p, b) && !le(b, p))));
+}
+
+void test04()
+{
+  auto p = a + 8;
+  std::greater_equal<int*> ge;
+  VERIFY((ge(p, b) && !ge(b, p) && !(ge(p, b) && ge(b, p)))
+        || (!ge(p, b) && ge(b, p) && !(ge(p, b) && ge(b, p)))
+        || (ge(p, b) && ge(b, p) && !(!ge(p, b) && !ge(b, p))));
+}
+
+int main()
+{
+  test01();
+  test02();
+  test03();
+  test04();
+}
diff --git 
a/libstdc++-v3/testsuite/20_util/function_objects/pointer_comparison_opt.cc 
b/libstdc++-v3/testsuite/20_util/function_objects/pointer_comparison_opt.cc
new file mode 100644
index 0000000..d6f33db
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/function_objects/pointer_comparison_opt.cc
@@ -0,0 +1,26 @@
+// { dg-options "-O2" }
+// { dg-do run { target c++11 } }
+
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// 20.9.5-20.9.9
+
+#include <functional>
+#include <testsuite_hooks.h>
+
+#include "pointer_comparison.inl"

Reply via email to