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
12 // XFAIL: with_system_cxx_lib=macosx10.12
13 // XFAIL: with_system_cxx_lib=macosx10.11
14 // XFAIL: with_system_cxx_lib=macosx10.10
15 // XFAIL: with_system_cxx_lib=macosx10.9
16 // XFAIL: with_system_cxx_lib=macosx10.7
17 // XFAIL: with_system_cxx_lib=macosx10.8
21 // any(any &&) noexcept;
23 #include <experimental/any>
25 #include <type_traits>
28 #include "experimental_any_helpers.h"
29 #include "count_new.hpp"
30 #include "test_macros.h"
32 using std::experimental::any;
33 using std::experimental::any_cast;
35 // Moves are always noexcept. The throws_on_move object
36 // must be stored dynamically so the pointer is moved and
37 // not the stored object.
38 void test_move_does_not_throw()
40 #if !defined(TEST_HAS_NO_EXCEPTIONS)
41 assert(throws_on_move::count == 0);
45 assert(throws_on_move::count == 2);
46 // No allocations should be performed after this point.
47 DisableAllocationGuard g; ((void)g);
49 any const a2(std::move(a));
51 assertContains<throws_on_move>(a2, 42);
55 assert(throws_on_move::count == 1);
58 assert(throws_on_move::count == 0);
62 void test_move_empty() {
63 DisableAllocationGuard g; ((void)g); // no allocations should be performed.
66 any a2(std::move(a1));
74 assert(Type::count == 0);
78 assert(Type::count == 1);
79 assert(Type::copied == 0);
80 assert(Type::moved == 1);
82 // Moving should not perform allocations since it must be noexcept.
83 DisableAllocationGuard g; ((void)g);
87 assert(Type::moved >= 1); // zero or more move operations can be performed.
88 assert(Type::copied == 0); // no copies can be performed.
89 assert(Type::count == 1);
90 assertEmpty(a); // Moves are always destructive.
91 assertContains<Type>(a2, 42);
93 assert(Type::count == 0);
101 std::is_nothrow_move_constructible<any>::value
102 , "any must be nothrow move constructible"
108 test_move_does_not_throw();