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 // <unordered_set>
10 
11 // ~unordered_set() // implied noexcept;
12 
13 // UNSUPPORTED: c++03
14 
15 #include <unordered_set>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 #include "MoveOnly.h"
20 #include "test_allocator.h"
21 
22 template <class T>
23 struct some_comp
24 {
25     typedef T value_type;
26     ~some_comp() noexcept(false);
operator ()some_comp27     bool operator()(const T&, const T&) const { return false; }
28 };
29 
30 template <class T>
31 struct some_hash
32 {
33     typedef T value_type;
34     some_hash();
35     some_hash(const some_hash&);
36     ~some_hash() noexcept(false);
37     std::size_t operator()(T const&) const;
38 };
39 
main(int,char **)40 int main(int, char**)
41 {
42     {
43         typedef std::unordered_set<MoveOnly> C;
44         static_assert(std::is_nothrow_destructible<C>::value, "");
45     }
46     {
47         typedef std::unordered_set<MoveOnly, std::hash<MoveOnly>,
48                            std::equal_to<MoveOnly>, test_allocator<MoveOnly>> C;
49         static_assert(std::is_nothrow_destructible<C>::value, "");
50     }
51     {
52         typedef std::unordered_set<MoveOnly, std::hash<MoveOnly>,
53                           std::equal_to<MoveOnly>, other_allocator<MoveOnly>> C;
54         static_assert(std::is_nothrow_destructible<C>::value, "");
55     }
56 #if defined(_LIBCPP_VERSION)
57     {
58         typedef std::unordered_set<MoveOnly, some_hash<MoveOnly>> C;
59         static_assert(!std::is_nothrow_destructible<C>::value, "");
60     }
61     {
62         typedef std::unordered_set<MoveOnly, std::hash<MoveOnly>,
63                                                          some_comp<MoveOnly>> C;
64         static_assert(!std::is_nothrow_destructible<C>::value, "");
65     }
66 #endif // _LIBCPP_VERSION
67 
68   return 0;
69 }
70