1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14
10 
11 // Throwing bad_any_cast is supported starting in macosx10.13
12 // XFAIL: with_system_cxx_lib=macosx10.12 && !no-exceptions
13 // XFAIL: with_system_cxx_lib=macosx10.11 && !no-exceptions
14 // XFAIL: with_system_cxx_lib=macosx10.10 && !no-exceptions
15 // XFAIL: with_system_cxx_lib=macosx10.9 && !no-exceptions
16 
17 // <any>
18 
19 // any::reset() noexcept
20 
21 #include <any>
22 #include <cassert>
23 
24 #include "test_macros.h"
25 #include "any_helpers.h"
26 
main(int,char **)27 int main(int, char**)
28 {
29     using std::any;
30     using std::any_cast;
31     // empty
32     {
33         any a;
34 
35         // noexcept check
36         static_assert(
37             noexcept(a.reset())
38           , "any.reset() must be noexcept"
39           );
40 
41         assertEmpty(a);
42 
43         a.reset();
44 
45         assertEmpty(a);
46     }
47     // small object
48     {
49         any a((small(1)));
50         assert(small::count == 1);
51         assertContains<small>(a, 1);
52 
53         a.reset();
54 
55         assertEmpty<small>(a);
56         assert(small::count == 0);
57     }
58     // large object
59     {
60         any a(large(1));
61         assert(large::count == 1);
62         assertContains<large>(a, 1);
63 
64         a.reset();
65 
66         assertEmpty<large>(a);
67         assert(large::count == 0);
68     }
69 
70   return 0;
71 }
72