aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2018-03-22 14:23:27 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2018-03-22 14:23:27 +0000
commit7c69a7d9bdabb4d0200718edfff54a139e488b7f (patch)
tree7afede0eb45c1aeb24a6377f8775913809408748
parentece7d31f429306945b5fb8b31496d2725bd74a13 (diff)
downloadgcc-7c69a7d9bdabb4d0200718edfff54a139e488b7f.zip
gcc-7c69a7d9bdabb4d0200718edfff54a139e488b7f.tar.gz
gcc-7c69a7d9bdabb4d0200718edfff54a139e488b7f.tar.bz2
PR libstdc++/85040 fix std::less<void> etc. ambiguities
PR libstdc++/85040 * include/bits/stl_function.h (greater::__not_overloaded) (less::__not_overloaded, greater_equal::__not_overloaded) (less_equal::__not_overloaded): Fix ambiguous specializations. * testsuite/20_util/function_objects/comparisons_pointer.cc: Add tests for type with overlaoded operators. From-SVN: r258773
-rw-r--r--libstdc++-v3/ChangeLog9
-rw-r--r--libstdc++-v3/include/bits/stl_function.h76
-rw-r--r--libstdc++-v3/testsuite/20_util/function_objects/comparisons_pointer.cc34
3 files changed, 79 insertions, 40 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 2fe3ad1..5d2620d 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,12 @@
+2018-03-22 Jonathan Wakely <jwakely@redhat.com>
+
+ PR libstdc++/85040
+ * include/bits/stl_function.h (greater::__not_overloaded)
+ (less::__not_overloaded, greater_equal::__not_overloaded)
+ (less_equal::__not_overloaded): Fix ambiguous specializations.
+ * testsuite/20_util/function_objects/comparisons_pointer.cc: Add
+ tests for type with overlaoded operators.
+
2018-03-22 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
PR libstdc++/77691
diff --git a/libstdc++-v3/include/bits/stl_function.h b/libstdc++-v3/include/bits/stl_function.h
index 0affaf7..9e81ad3 100644
--- a/libstdc++-v3/include/bits/stl_function.h
+++ b/libstdc++-v3/include/bits/stl_function.h
@@ -523,15 +523,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static_cast<const volatile void*>(std::forward<_Up>(__u)));
}
- template<typename _Tp, typename _Up, typename = void>
- struct __not_overloaded;
-
- // False if we can call operator>(T,U)
- template<typename _Tp, typename _Up>
- struct __not_overloaded<_Tp, _Up, __void_t<
- decltype(operator>(std::declval<_Tp>(), std::declval<_Up>()))>>
- : false_type { };
-
+ // True if there is no viable operator> member function.
template<typename _Tp, typename _Up, typename = void>
struct __not_overloaded2 : true_type { };
@@ -541,8 +533,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
decltype(std::declval<_Tp>().operator>(std::declval<_Up>()))>>
: false_type { };
+ // True if there is no overloaded operator> for these operands.
+ template<typename _Tp, typename _Up, typename = void>
+ struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
+
+ // False if we can call operator>(T,U)
template<typename _Tp, typename _Up>
- struct __not_overloaded<_Tp, _Up> : __not_overloaded2<_Tp, _Up> { };
+ struct __not_overloaded<_Tp, _Up, __void_t<
+ decltype(operator>(std::declval<_Tp>(), std::declval<_Up>()))>>
+ : false_type { };
template<typename _Tp, typename _Up>
using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
@@ -586,15 +585,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static_cast<const volatile void*>(std::forward<_Up>(__u)));
}
- template<typename _Tp, typename _Up, typename = void>
- struct __not_overloaded;
-
- // False if we can call operator<(T,U)
- template<typename _Tp, typename _Up>
- struct __not_overloaded<_Tp, _Up, __void_t<
- decltype(operator<(std::declval<_Tp>(), std::declval<_Up>()))>>
- : false_type { };
-
+ // True if there is no viable operator< member function.
template<typename _Tp, typename _Up, typename = void>
struct __not_overloaded2 : true_type { };
@@ -604,8 +595,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
decltype(std::declval<_Tp>().operator<(std::declval<_Up>()))>>
: false_type { };
+ // True if there is no overloaded operator< for these operands.
+ template<typename _Tp, typename _Up, typename = void>
+ struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
+
+ // False if we can call operator<(T,U)
template<typename _Tp, typename _Up>
- struct __not_overloaded<_Tp, _Up> : __not_overloaded2<_Tp, _Up> { };
+ struct __not_overloaded<_Tp, _Up, __void_t<
+ decltype(operator<(std::declval<_Tp>(), std::declval<_Up>()))>>
+ : false_type { };
template<typename _Tp, typename _Up>
using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
@@ -649,15 +647,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static_cast<const volatile void*>(std::forward<_Up>(__u)));
}
- template<typename _Tp, typename _Up, typename = void>
- struct __not_overloaded;
-
- // False if we can call operator>=(T,U)
- template<typename _Tp, typename _Up>
- struct __not_overloaded<_Tp, _Up, __void_t<
- decltype(operator>=(std::declval<_Tp>(), std::declval<_Up>()))>>
- : false_type { };
-
+ // True if there is no viable operator>= member function.
template<typename _Tp, typename _Up, typename = void>
struct __not_overloaded2 : true_type { };
@@ -667,8 +657,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
decltype(std::declval<_Tp>().operator>=(std::declval<_Up>()))>>
: false_type { };
+ // True if there is no overloaded operator>= for these operands.
+ template<typename _Tp, typename _Up, typename = void>
+ struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
+
+ // False if we can call operator>=(T,U)
template<typename _Tp, typename _Up>
- struct __not_overloaded<_Tp, _Up> : __not_overloaded2<_Tp, _Up> { };
+ struct __not_overloaded<_Tp, _Up, __void_t<
+ decltype(operator>=(std::declval<_Tp>(), std::declval<_Up>()))>>
+ : false_type { };
template<typename _Tp, typename _Up>
using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
@@ -712,15 +709,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static_cast<const volatile void*>(std::forward<_Up>(__u)));
}
- template<typename _Tp, typename _Up, typename = void>
- struct __not_overloaded;
-
- // False if we can call operator<=(T,U)
- template<typename _Tp, typename _Up>
- struct __not_overloaded<_Tp, _Up, __void_t<
- decltype(operator<=(std::declval<_Tp>(), std::declval<_Up>()))>>
- : false_type { };
-
+ // True if there is no viable operator<= member function.
template<typename _Tp, typename _Up, typename = void>
struct __not_overloaded2 : true_type { };
@@ -730,8 +719,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
decltype(std::declval<_Tp>().operator<=(std::declval<_Up>()))>>
: false_type { };
+ // True if there is no overloaded operator<= for these operands.
+ template<typename _Tp, typename _Up, typename = void>
+ struct __not_overloaded : __not_overloaded2<_Tp, _Up> { };
+
+ // False if we can call operator<=(T,U)
template<typename _Tp, typename _Up>
- struct __not_overloaded<_Tp, _Up> : __not_overloaded2<_Tp, _Up> { };
+ struct __not_overloaded<_Tp, _Up, __void_t<
+ decltype(operator<=(std::declval<_Tp>(), std::declval<_Up>()))>>
+ : false_type { };
template<typename _Tp, typename _Up>
using __ptr_cmp = __and_<__not_overloaded<_Tp, _Up>,
diff --git a/libstdc++-v3/testsuite/20_util/function_objects/comparisons_pointer.cc b/libstdc++-v3/testsuite/20_util/function_objects/comparisons_pointer.cc
index 474190c..7cec294 100644
--- a/libstdc++-v3/testsuite/20_util/function_objects/comparisons_pointer.cc
+++ b/libstdc++-v3/testsuite/20_util/function_objects/comparisons_pointer.cc
@@ -195,6 +195,39 @@ test05()
#endif
}
+struct Overloaded {
+ bool operator>(int) { return true; }
+ bool operator<(int) { return false; }
+ bool operator>=(int) { return true; }
+ bool operator<=(int) { return false; }
+};
+bool operator>(Overloaded, Overloaded) { return false; }
+bool operator<(Overloaded, Overloaded) { return false; }
+bool operator>=(Overloaded, Overloaded) { return true; }
+bool operator<=(Overloaded, Overloaded) { return true; }
+
+void
+test06()
+{
+#if __cplusplus >= 201402L
+ std::greater<void> gt;
+ std::less<void> lt;
+ std::greater_equal<void> ge;
+ std::less_equal<void> le;
+
+ Overloaded o;
+ VERIFY( !gt(o, o) );
+ VERIFY( !lt(o, o) );
+ VERIFY( ge(o, o) );
+ VERIFY( le(o, o) );
+
+ VERIFY( gt(o, 1) );
+ VERIFY( !lt(o, 1) );
+ VERIFY( ge(o, 1) );
+ VERIFY( !le(o, 1) );
+#endif
+}
+
int
main()
{
@@ -203,4 +236,5 @@ main()
test03();
test04();
test05();
+ test06();
}