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