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
13 // any& operator=(any &&);
15 // Test move assignment.
20 #include "any_helpers.h"
21 #include "test_macros.h"
23 template <class LHS
, class RHS
>
24 void test_move_assign() {
25 assert(LHS::count
== 0);
26 assert(RHS::count
== 0);
33 assert(LHS::count
== 2);
34 assert(RHS::count
== 2);
38 assert(LHS::count
== 1);
39 assert(RHS::count
== 2 + a2
.has_value());
40 LIBCPP_ASSERT(RHS::count
== 2); // libc++ leaves the object empty
42 assertContains
<RHS
>(a
, 2);
44 assertContains
<RHS
>(a2
, 0);
45 LIBCPP_ASSERT(!a2
.has_value());
47 assert(LHS::count
== 0);
48 assert(RHS::count
== 0);
52 void test_move_assign_empty() {
53 assert(LHS::count
== 0);
58 assert(LHS::count
== 1);
62 assert(LHS::count
== 1 + a2
.has_value());
63 LIBCPP_ASSERT(LHS::count
== 1);
65 assertContains
<LHS
>(a
, 1);
67 assertContains
<LHS
>(a2
, 0);
68 LIBCPP_ASSERT(!a2
.has_value());
70 assert(LHS::count
== 0);
75 assert(LHS::count
== 1);
79 assert(LHS::count
== 0);
84 assert(LHS::count
== 0);
87 void test_move_assign_noexcept() {
90 ASSERT_NOEXCEPT(a1
= std::move(a2
));
93 int main(int, char**) {
94 test_move_assign_noexcept();
95 test_move_assign
<small1
, small2
>();
96 test_move_assign
<large1
, large2
>();
97 test_move_assign
<small
, large
>();
98 test_move_assign
<large
, small
>();
99 test_move_assign_empty
<small
>();
100 test_move_assign_empty
<large
>();