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
23 #include <experimental/any>
26 #include "experimental_any_helpers.h"
27 #include "count_new.hpp"
28 #include "test_macros.h"
30 using std::experimental::any;
31 using std::experimental::any_cast;
34 void test_copy_throws() {
35 #if !defined(TEST_HAS_NO_EXCEPTIONS)
36 assert(Type::count == 0);
38 any const a((Type(42)));
39 assert(Type::count == 1);
43 } catch (my_any_exception const &) {
48 assert(Type::count == 1);
49 assertContains<Type>(a, 42);
51 assert(Type::count == 0);
55 void test_copy_empty() {
56 DisableAllocationGuard g; ((void)g); // No allocations should occur.
67 // Copying small types should not perform any allocations.
68 DisableAllocationGuard g(isSmallType<Type>()); ((void)g);
69 assert(Type::count == 0);
73 assert(Type::count == 1);
74 assert(Type::copied == 0);
78 assert(Type::copied == 1);
79 assert(Type::count == 2);
80 assertContains<Type>(a, 42);
81 assertContains<Type>(a, 42);
83 // Modify a and check that a2 is unchanged
84 modifyValue<Type>(a, -1);
85 assertContains<Type>(a, -1);
86 assertContains<Type>(a2, 42);
88 // modify a2 and check that a is unchanged
89 modifyValue<Type>(a2, 999);
90 assertContains<Type>(a, -1);
91 assertContains<Type>(a2, 999);
93 // clear a and check that a2 is unchanged
96 assertContains<Type>(a2, 999);
98 assert(Type::count == 0);
105 test_copy_throws<small_throws_on_copy>();
106 test_copy_throws<large_throws_on_copy>();