@@ -1271,10 +1271,11 @@ namespace __detail::__variant
operator== [[nodiscard]] (const variant<_Types...>& __lhs,
const variant<_Types...>& __rhs)
{
- return __detail::__variant::__compare(true, __lhs, __rhs,
- [](auto&& __l, auto&& __r) {
- return __l == __r;
- });
+ namespace __variant = __detail::__variant;
+ return __variant::__compare(true, __lhs, __rhs,
+ [](auto&& __l, auto&& __r) -> bool {
+ return __l == __r;
+ });
}
template<typename... _Types>
@@ -1286,10 +1287,11 @@ namespace __detail::__variant
operator!= [[nodiscard]] (const variant<_Types...>& __lhs,
const variant<_Types...>& __rhs)
{
- return __detail::__variant::__compare(true, __lhs, __rhs,
- [](auto&& __l, auto&& __r) {
- return __l != __r;
- });
+ namespace __variant = __detail::__variant;
+ return __variant::__compare(true, __lhs, __rhs,
+ [](auto&& __l, auto&& __r) -> bool {
+ return __l != __r;
+ });
}
template<typename... _Types>
@@ -1301,10 +1303,11 @@ namespace __detail::__variant
operator< [[nodiscard]] (const variant<_Types...>& __lhs,
const variant<_Types...>& __rhs)
{
- return __detail::__variant::__compare(true, __lhs, __rhs,
- [](auto&& __l, auto&& __r) {
- return __l < __r;
- });
+ namespace __variant = __detail::__variant;
+ return __variant::__compare(true, __lhs, __rhs,
+ [](auto&& __l, auto&& __r) -> bool {
+ return __l < __r;
+ });
}
template<typename... _Types>
@@ -1316,10 +1319,11 @@ namespace __detail::__variant
operator<= [[nodiscard]] (const variant<_Types...>& __lhs,
const variant<_Types...>& __rhs)
{
- return __detail::__variant::__compare(true, __lhs, __rhs,
- [](auto&& __l, auto&& __r) {
- return __l <= __r;
- });
+ namespace __variant = __detail::__variant;
+ return __variant::__compare(true, __lhs, __rhs,
+ [](auto&& __l, auto&& __r) -> bool {
+ return __l <= __r;
+ });
}
template<typename... _Types>
@@ -1331,10 +1335,11 @@ namespace __detail::__variant
operator> [[nodiscard]] (const variant<_Types...>& __lhs,
const variant<_Types...>& __rhs)
{
- return __detail::__variant::__compare(true, __lhs, __rhs,
- [](auto&& __l, auto&& __r) {
- return __l > __r;
- });
+ namespace __variant = __detail::__variant;
+ return __variant::__compare(true, __lhs, __rhs,
+ [](auto&& __l, auto&& __r) -> bool {
+ return __l > __r;
+ });
}
template<typename... _Types>
@@ -1346,10 +1351,11 @@ namespace __detail::__variant
operator>= [[nodiscard]] (const variant<_Types...>& __lhs,
const variant<_Types...>& __rhs)
{
- return __detail::__variant::__compare(true, __lhs, __rhs,
- [](auto&& __l, auto&& __r) {
- return __l >= __r;
- });
+ namespace __variant = __detail::__variant;
+ return __variant::__compare(true, __lhs, __rhs,
+ [](auto&& __l, auto&& __r) -> bool {
+ return __l >= __r;
+ });
}
constexpr bool operator==(monostate, monostate) noexcept { return true; }
@@ -1363,10 +1369,11 @@ namespace __detail::__variant
{
common_comparison_category_t<compare_three_way_result_t<_Types>...> __ret
= strong_ordering::equal;
- return __detail::__variant::__compare(__ret, __v, __w,
- [](auto&& __l, auto&& __r) {
- return __l <=> __r;
- });
+ namespace __variant = __detail::__variant;
+ return __variant::__compare(__ret, __v, __w,
+ [](auto&& __l, auto&& __r) {
+ return __l <=> __r;
+ });
}
constexpr strong_ordering
new file mode 100644
@@ -0,0 +1,36 @@
+// { dg-do compile { target c++17 } }
+// PR libstdc++/115145
+// lambda in rewritten std::variant comparisons does not specify return type
+
+#include <variant>
+
+struct Bool {
+ operator bool() & { return val; }
+ const bool val;
+};
+
+Bool t{true}, f{false};
+
+struct A {
+ Bool& operator==(const A&) const { return t; }
+ Bool& operator!=(const A&) const { return f; }
+ Bool& operator<(const A&) const { return f; }
+ Bool& operator>(const A&) const { return f; }
+ Bool& operator<=(const A&) const { return t; }
+ Bool& operator>=(const A&) const { return t; }
+};
+
+bool check_bool(bool);
+template<typename T> void check_bool(T) = delete;
+
+void
+test_pr115145()
+{
+ std::variant<A> v;
+ check_bool( v == v );
+ check_bool( !(v != v) );
+ check_bool( !(v < v) );
+ check_bool( !(v > v) );
+ check_bool( v <= v );
+ check_bool( v >= v );
+}