brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 92e2fef Raw
85 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++14, c++17, c++2010 11// template<>12// class bad_expected_access<void> : public exception {13// protected:14//   bad_expected_access() noexcept;15//   bad_expected_access(const bad_expected_access&) noexcept;16//   bad_expected_access(bad_expected_access&&) noexcept;17//   bad_expected_access& operator=(const bad_expected_access&) noexcept;18//   bad_expected_access& operator=(bad_expected_access&&) noexcept;19//   ~bad_expected_access();20//21// public:22//   const char* what() const noexcept override;23// };24 25#include <cassert>26#include <exception>27#include <expected>28#include <type_traits>29#include <utility>30 31#include "test_macros.h"32 33struct Inherit : std::bad_expected_access<void> {};34 35int main(int, char**) {36  // base class37  static_assert(std::is_base_of_v<std::exception, std::bad_expected_access<void>>);38 39  // default constructor40  {41    Inherit exc;42    ASSERT_NOEXCEPT(Inherit());43  }44 45  // copy constructor46  {47    Inherit exc;48    Inherit copy(exc);49    ASSERT_NOEXCEPT(Inherit(exc));50  }51 52  // move constructor53  {54    Inherit exc;55    Inherit copy(std::move(exc));56    ASSERT_NOEXCEPT(Inherit(std::move(exc)));57  }58 59  // copy assignment60  {61    Inherit exc;62    Inherit copy;63    [[maybe_unused]] Inherit& result = (copy = exc);64    ASSERT_NOEXCEPT(copy = exc);65  }66 67  // move assignment68  {69    Inherit exc;70    Inherit copy;71    [[maybe_unused]] Inherit& result = (copy = std::move(exc));72    ASSERT_NOEXCEPT(copy = std::move(exc));73  }74 75  // what()76  {77    Inherit exc;78    char const* what = exc.what();79    assert(what != nullptr);80    ASSERT_NOEXCEPT(exc.what());81  }82 83  return 0;84}85