1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03, c++11, c++14
12 // XFAIL: availability=macosx10.13
13 // XFAIL: availability=macosx10.12
14 // XFAIL: availability=macosx10.11
15 // XFAIL: availability=macosx10.10
16 // XFAIL: availability=macosx10.9
17 // XFAIL: availability=macosx10.8
18 // XFAIL: availability=macosx10.7
22 // any(any &&) noexcept;
26 #include <type_traits>
29 #include "any_helpers.h"
30 #include "count_new.hpp"
31 #include "test_macros.h"
36 // Moves are always noexcept. The throws_on_move object
37 // must be stored dynamically so the pointer is moved and
38 // not the stored object.
39 void test_move_does_not_throw()
41 #if !defined(TEST_HAS_NO_EXCEPTIONS)
42 assert(throws_on_move::count == 0);
46 assert(throws_on_move::count == 2);
47 // No allocations should be performed after this point.
48 DisableAllocationGuard g; ((void)g);
50 any const a2(std::move(a));
52 assertContains<throws_on_move>(a2, 42);
56 assert(throws_on_move::count == 1);
59 assert(throws_on_move::count == 0);
63 void test_move_empty() {
64 DisableAllocationGuard g; ((void)g); // no allocations should be performed.
67 any a2(std::move(a1));
75 assert(Type::count == 0);
79 assert(Type::count == 1);
80 assert(Type::copied == 0);
81 assert(Type::moved == 1);
83 // Moving should not perform allocations since it must be noexcept.
84 DisableAllocationGuard g; ((void)g);
88 assert(Type::moved == 1 || Type::moved == 2); // zero or more move operations can be performed.
89 assert(Type::copied == 0); // no copies can be performed.
90 assert(Type::count == 1 + a.has_value());
91 assertContains<Type>(a2, 42);
92 LIBCPP_ASSERT(!a.has_value()); // Moves are always destructive.
94 assertContains<Type>(a, 0);
96 assert(Type::count == 0);
104 std::is_nothrow_move_constructible<any>::value
105 , "any must be nothrow move constructible"
111 test_move_does_not_throw();