1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
13 // template <class ...Types>
15 // operator==(variant<Types...> const&, variant<Types...> const&) noexcept;
17 // template <class ...Types>
19 // operator!=(variant<Types...> const&, variant<Types...> const&) noexcept;
21 // template <class ...Types>
23 // operator<(variant<Types...> const&, variant<Types...> const&) noexcept;
25 // template <class ...Types>
27 // operator>(variant<Types...> const&, variant<Types...> const&) noexcept;
29 // template <class ...Types>
31 // operator<=(variant<Types...> const&, variant<Types...> const&) noexcept;
33 // template <class ...Types>
35 // operator>=(variant<Types...> const&, variant<Types...> const&) noexcept;
38 #include <type_traits>
42 #include "test_macros.h"
45 struct MyBoolExplicit
{
47 constexpr explicit MyBoolExplicit(bool v
) : value(v
) {}
48 constexpr explicit operator bool() const noexcept
{ return value
; }
51 struct ComparesToMyBoolExplicit
{
54 inline constexpr MyBoolExplicit
operator==(const ComparesToMyBoolExplicit
& LHS
, const ComparesToMyBoolExplicit
& RHS
) noexcept
{
55 return MyBoolExplicit(LHS
.value
== RHS
.value
);
57 inline constexpr MyBoolExplicit
operator!=(const ComparesToMyBoolExplicit
& LHS
, const ComparesToMyBoolExplicit
& RHS
) noexcept
{
58 return MyBoolExplicit(LHS
.value
!= RHS
.value
);
60 inline constexpr MyBoolExplicit
operator<(const ComparesToMyBoolExplicit
& LHS
, const ComparesToMyBoolExplicit
& RHS
) noexcept
{
61 return MyBoolExplicit(LHS
.value
< RHS
.value
);
63 inline constexpr MyBoolExplicit
operator<=(const ComparesToMyBoolExplicit
& LHS
, const ComparesToMyBoolExplicit
& RHS
) noexcept
{
64 return MyBoolExplicit(LHS
.value
<= RHS
.value
);
66 inline constexpr MyBoolExplicit
operator>(const ComparesToMyBoolExplicit
& LHS
, const ComparesToMyBoolExplicit
& RHS
) noexcept
{
67 return MyBoolExplicit(LHS
.value
> RHS
.value
);
69 inline constexpr MyBoolExplicit
operator>=(const ComparesToMyBoolExplicit
& LHS
, const ComparesToMyBoolExplicit
& RHS
) noexcept
{
70 return MyBoolExplicit(LHS
.value
>= RHS
.value
);
74 int main(int, char**) {
75 using V
= std::variant
<int, ComparesToMyBoolExplicit
>;
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}}