xref: /llvm-project/libcxx/test/std/utilities/expected/expected.unexpected/ctor/ctor.move.pass.cpp (revision 6a54dfbfe534276d644d7f9c027f0deeb748dd53)
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 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10 
11 // constexpr unexpected(unexpected&&) = default;
12 
13 #include <cassert>
14 #include <expected>
15 #include <utility>
16 
17 struct Error {
18   int i;
19   constexpr Error(int ii) : i(ii) {}
20   constexpr Error(Error&& other) : i(other.i) {other.i = 0;}
21 };
22 
23 constexpr bool test() {
24   std::unexpected<Error> unex(5);
25   auto unex2 = std::move(unex);
26   assert(unex2.error().i == 5);
27   assert(unex.error().i == 0);
28   return true;
29 }
30 
31 int main(int, char**) {
32   test();
33   static_assert(test());
34   return 0;
35 }
36