1 //===----------------------------------------------------------------------===//
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
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.
19 #include <type_traits>
22 #include "test_macros.h"
24 // Test Remarks: If is_trivially_destructible_v<E> is true, then this destructor is a trivial destructor.
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
{
34 constexpr TrackedDestroy(bool& b
) : destroyed(b
) {}
35 constexpr ~TrackedDestroy() { destroyed
= true; }
38 constexpr bool test() {
40 { [[maybe_unused
]] std::expected
<void, TrackedDestroy
> e(std::in_place
); }
44 bool errorDestroyed
= false;
45 { [[maybe_unused
]] std::expected
<void, TrackedDestroy
> e(std::unexpect
, errorDestroyed
); }
46 assert(errorDestroyed
);
52 int main(int, char**) {
54 static_assert(test());