brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · 392a234 Raw
90 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410 11// <variant>12 13// template <class ...Types>14// constexpr bool15// operator==(variant<Types...> const&, variant<Types...> const&) noexcept;16//17// template <class ...Types>18// constexpr bool19// operator!=(variant<Types...> const&, variant<Types...> const&) noexcept;20//21// template <class ...Types>22// constexpr bool23// operator<(variant<Types...> const&, variant<Types...> const&) noexcept;24//25// template <class ...Types>26// constexpr bool27// operator>(variant<Types...> const&, variant<Types...> const&) noexcept;28//29// template <class ...Types>30// constexpr bool31// operator<=(variant<Types...> const&, variant<Types...> const&) noexcept;32//33// template <class ...Types>34// constexpr bool35// 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#if TEST_STD_VER >= 2645// expected-no-diagnostics46#else47struct MyBoolExplicit {48  bool value;49  constexpr explicit MyBoolExplicit(bool v) : value(v) {}50  constexpr explicit operator bool() const noexcept { return value; }51};52 53struct ComparesToMyBoolExplicit {54  int value = 0;55};56inline constexpr MyBoolExplicit operator==(const ComparesToMyBoolExplicit& LHS, const ComparesToMyBoolExplicit& RHS) noexcept {57  return MyBoolExplicit(LHS.value == RHS.value);58}59inline constexpr MyBoolExplicit operator!=(const ComparesToMyBoolExplicit& LHS, const ComparesToMyBoolExplicit& RHS) noexcept {60  return MyBoolExplicit(LHS.value != RHS.value);61}62inline constexpr MyBoolExplicit operator<(const ComparesToMyBoolExplicit& LHS, const ComparesToMyBoolExplicit& RHS) noexcept {63  return MyBoolExplicit(LHS.value < RHS.value);64}65inline constexpr MyBoolExplicit operator<=(const ComparesToMyBoolExplicit& LHS, const ComparesToMyBoolExplicit& RHS) noexcept {66  return MyBoolExplicit(LHS.value <= RHS.value);67}68inline constexpr MyBoolExplicit operator>(const ComparesToMyBoolExplicit& LHS, const ComparesToMyBoolExplicit& RHS) noexcept {69  return MyBoolExplicit(LHS.value > RHS.value);70}71inline constexpr MyBoolExplicit operator>=(const ComparesToMyBoolExplicit& LHS, const ComparesToMyBoolExplicit& RHS) noexcept {72  return MyBoolExplicit(LHS.value >= RHS.value);73}74 75void test() {76  using V = std::variant<int, ComparesToMyBoolExplicit>;77  V v1(42);78  V v2(101);79  // expected-error-re@variant:* 6 {{static assertion failed{{.*}}the relational operator does not return a type which is implicitly convertible to bool}}80  // expected-error@variant:* 6 {{no viable conversion}}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  (void)(v1 >= v2); // expected-note {{here}}87}88 89#endif90