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// constexpr unexpected& operator=(unexpected&&) = default;
11
12#include <cassert>
13#include <expected>
14#include <utility>
15
16struct Error {
17 int i;
18 constexpr Error(int ii) : i(ii) {}
19 constexpr Error& operator=(Error&& other) {
20 i = other.i;
21 other.i = 0;
22 return *this;
23 }
24};
25
26constexpr bool test() {
27 std::unexpected<Error> unex1(4);
28 std::unexpected<Error> unex2(5);
29 unex1 = std::move(unex2);
30 assert(unex1.error().i == 5);
31 assert(unex2.error().i == 0);
32 return true;
33}
34
35int main(int, char**) {
36 test();
37 static_assert(test());
38 return 0;
39}
40

source code of libcxx/test/std/utilities/expected/expected.unexpected/assign/assign.move.pass.cpp