Debian Codegraph @

libcxx/test/std/utilities/expected/expected.bad/void-specialization.pass.cpp

raw
1 //===----------------------------------------------------------------------===//
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7
8 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
9
10 // template<>
11 // class bad_expected_access<void> : public exception {
12 // protected:
13 // bad_expected_access() noexcept;
14 // bad_expected_access(const bad_expected_access&) noexcept;
15 // bad_expected_access(bad_expected_access&&) noexcept;
16 // bad_expected_access& operator=(const bad_expected_access&) noexcept;
17 // bad_expected_access& operator=(bad_expected_access&&) noexcept;
18 // ~bad_expected_access();
19 //
20 // public:
21 // const char* what() const noexcept override;
22 // };
23
24 #include <cassert>
25 #include <exception>
26 #include <expected>
27 #include <type_traits>
28 #include <utility>
29
30 #include "test_macros.h"
31
32 struct Inherit : std::bad_expected_access<void> {};
33
34 int main(int, char**) {
35 // base class
36 static_assert(std::is_base_of_v<std::exception, std::bad_expected_access<void>>);
37
38 // default constructor
39 {
40 Inherit exc;
41 ASSERT_NOEXCEPT(Inherit());
42 }
43
44 // copy constructor
45 {
46 Inherit exc;
47 Inherit copy(exc);
48 ASSERT_NOEXCEPT(Inherit(exc));
49 }
50
51 // move constructor
52 {
53 Inherit exc;
54 Inherit copy(std::move(exc));
55 ASSERT_NOEXCEPT(Inherit(std::move(exc)));
56 }
57
58 // copy assignment
59 {
60 Inherit exc;
61 Inherit copy;
62 [[maybe_unused]] Inherit& result = (copy = exc);
63 ASSERT_NOEXCEPT(copy = exc);
64 }
65
66 // move assignment
67 {
68 Inherit exc;
69 Inherit copy;
70 [[maybe_unused]] Inherit& result = (copy = std::move(exc));
71 ASSERT_NOEXCEPT(copy = std::move(exc));
72 }
73
74 // what()
75 {
76 Inherit exc;
77 char const* what = exc.what();
78 assert(what != nullptr);
79 ASSERT_NOEXCEPT(exc.what());
80 }
81
82 return 0;
83 }