Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / variant / variant.relops / relops_bool_conv.verify.cpp
blob64248171d11469a869b0f2329667f54f188f1d92
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
11 // <variant>
13 // template <class ...Types>
14 // constexpr bool
15 // operator==(variant<Types...> const&, variant<Types...> const&) noexcept;
17 // template <class ...Types>
18 // constexpr bool
19 // operator!=(variant<Types...> const&, variant<Types...> const&) noexcept;
21 // template <class ...Types>
22 // constexpr bool
23 // operator<(variant<Types...> const&, variant<Types...> const&) noexcept;
25 // template <class ...Types>
26 // constexpr bool
27 // operator>(variant<Types...> const&, variant<Types...> const&) noexcept;
29 // template <class ...Types>
30 // constexpr bool
31 // operator<=(variant<Types...> const&, variant<Types...> const&) noexcept;
33 // template <class ...Types>
34 // constexpr bool
35 // operator>=(variant<Types...> const&, variant<Types...> const&) noexcept;
37 #include <cassert>
38 #include <type_traits>
39 #include <utility>
40 #include <variant>
42 #include "test_macros.h"
45 struct MyBoolExplicit {
46 bool value;
47 constexpr explicit MyBoolExplicit(bool v) : value(v) {}
48 constexpr explicit operator bool() const noexcept { return value; }
51 struct ComparesToMyBoolExplicit {
52 int value = 0;
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>;
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}}
87 return 0;