| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// UNSUPPORTED: c++03, c++11, c++14 |
| 10 |
|
| 11 |
// <variant> |
| 12 |
|
| 13 |
// template <class ...Types> |
| 14 |
// constexpr bool |
| 15 |
// operator==(variant<Types...> const&, variant<Types...> const&) noexcept; |
| 16 |
// |
| 17 |
// template <class ...Types> |
| 18 |
// constexpr bool |
| 19 |
// operator!=(variant<Types...> const&, variant<Types...> const&) noexcept; |
| 20 |
// |
| 21 |
// template <class ...Types> |
| 22 |
// constexpr bool |
| 23 |
// operator<(variant<Types...> const&, variant<Types...> const&) noexcept; |
| 24 |
// |
| 25 |
// template <class ...Types> |
| 26 |
// constexpr bool |
| 27 |
// operator>(variant<Types...> const&, variant<Types...> const&) noexcept; |
| 28 |
// |
| 29 |
// template <class ...Types> |
| 30 |
// constexpr bool |
| 31 |
// operator<=(variant<Types...> const&, variant<Types...> const&) noexcept; |
| 32 |
// |
| 33 |
// template <class ...Types> |
| 34 |
// constexpr bool |
| 35 |
// operator>=(variant<Types...> const&, variant<Types...> const&) noexcept; |
| 36 |
|
| 37 |
#include <cassert> |
| 38 |
#include <type_traits> |
| 39 |
#include <utility> |
| 40 |
#include <variant> |
| 41 |
|
| 42 |
#include "test_macros.h" |
| 43 |
|
| 44 |
|
| 45 |
struct MyBoolExplicit { |
| 46 |
bool value; |
| 47 |
constexpr explicit MyBoolExplicit(bool v) : value(v) {} |
| 48 |
constexpr explicit operator bool() const noexcept { return value; } |
| 49 |
}; |
| 50 |
|
| 51 |
struct ComparesToMyBoolExplicit { |
| 52 |
int value = 0; |
| 53 |
}; |
| 54 |
inline constexpr MyBoolExplicit operator==(const ComparesToMyBoolExplicit& LHS, const ComparesToMyBoolExplicit& RHS) noexcept { |
| 55 |
return MyBoolExplicit(LHS.value == RHS.value); |
| 56 |
} |
| 57 |
inline constexpr MyBoolExplicit operator!=(const ComparesToMyBoolExplicit& LHS, const ComparesToMyBoolExplicit& RHS) noexcept { |
| 58 |
return MyBoolExplicit(LHS.value != RHS.value); |
| 59 |
} |
| 60 |
inline constexpr MyBoolExplicit operator<(const ComparesToMyBoolExplicit& LHS, const ComparesToMyBoolExplicit& RHS) noexcept { |
| 61 |
return MyBoolExplicit(LHS.value < RHS.value); |
| 62 |
} |
| 63 |
inline constexpr MyBoolExplicit operator<=(const ComparesToMyBoolExplicit& LHS, const ComparesToMyBoolExplicit& RHS) noexcept { |
| 64 |
return MyBoolExplicit(LHS.value <= RHS.value); |
| 65 |
} |
| 66 |
inline constexpr MyBoolExplicit operator>(const ComparesToMyBoolExplicit& LHS, const ComparesToMyBoolExplicit& RHS) noexcept { |
| 67 |
return MyBoolExplicit(LHS.value > RHS.value); |
| 68 |
} |
| 69 |
inline constexpr MyBoolExplicit operator>=(const ComparesToMyBoolExplicit& LHS, const ComparesToMyBoolExplicit& RHS) noexcept { |
| 70 |
return MyBoolExplicit(LHS.value >= RHS.value); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
int main(int, char**) { |
| 75 |
using V = std::variant<int, ComparesToMyBoolExplicit>; |
| 76 |
V v1(42); |
| 77 |
V v2(101); |
| 78 |
// expected-error-re@variant:* 6 {{static assertion failed{{.*}}the relational operator does not return a type which is implicitly convertible to bool}} |
| 79 |
// expected-error@variant:* 6 {{no viable conversion}} |
| 80 |
(void)(v1 == v2); // expected-note {{here}} |
| 81 |
(void)(v1 != v2); // expected-note {{here}} |
| 82 |
(void)(v1 < v2); // expected-note {{here}} |
| 83 |
(void)(v1 <= v2); // expected-note {{here}} |
| 84 |
(void)(v1 > v2); // expected-note {{here}} |
| 85 |
(void)(v1 >= v2); // expected-note {{here}} |
| 86 |
|
| 87 |
return 0; |
| 88 |
} |