[memprof] Move YAML traits to MemProf.h (NFC) (#118668)
[llvm-project.git] / libcxx / test / std / utilities / expected / expected.void / dtor.pass.cpp
blob798149f45ae09eb893c77e3698ba2a2d7d82710b
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, c++17, c++20
11 // constexpr ~expected();
13 // Effects: If has_value() is false, destroys unex.
15 // Remarks: If is_trivially_destructible_v<E> is true, then this destructor is a trivial destructor.
17 #include <cassert>
18 #include <expected>
19 #include <type_traits>
20 #include <utility>
22 #include "test_macros.h"
24 // Test Remarks: If is_trivially_destructible_v<E> is true, then this destructor is a trivial destructor.
25 struct NonTrivial {
26 ~NonTrivial() {}
29 static_assert(std::is_trivially_destructible_v<std::expected<void, int>>);
30 static_assert(!std::is_trivially_destructible_v<std::expected<void, NonTrivial>>);
32 struct TrackedDestroy {
33 bool& destroyed;
34 constexpr TrackedDestroy(bool& b) : destroyed(b) {}
35 constexpr ~TrackedDestroy() { destroyed = true; }
38 constexpr bool test() {
39 // has value
40 { [[maybe_unused]] std::expected<void, TrackedDestroy> e(std::in_place); }
42 // has error
44 bool errorDestroyed = false;
45 { [[maybe_unused]] std::expected<void, TrackedDestroy> e(std::unexpect, errorDestroyed); }
46 assert(errorDestroyed);
49 return true;
52 int main(int, char**) {
53 test();
54 static_assert(test());
55 return 0;