Skip to content

Commit e3fbe14

Browse files
committed
Implement the first part of N4258: 'Cleaning up noexcept in the Library'. This patch deals with swapping containers, and implements a more strict noexcept specification (a conforming extension) than the standard mandates.
llvm-svn: 242056
1 parent 75a7e43 commit e3fbe14

File tree

26 files changed

+1311
-297
lines changed

26 files changed

+1311
-297
lines changed

libcxx/include/__hash_table

+18-46
Original file line numberDiff line numberDiff line change
@@ -985,12 +985,14 @@ public:
985985

986986
void swap(__hash_table& __u)
987987
_NOEXCEPT_(
988-
(!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value ||
989-
__is_nothrow_swappable<__pointer_allocator>::value) &&
990-
(!__node_traits::propagate_on_container_swap::value ||
991-
__is_nothrow_swappable<__node_allocator>::value) &&
992-
__is_nothrow_swappable<hasher>::value &&
993-
__is_nothrow_swappable<key_equal>::value);
988+
__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
989+
#if _LIBCPP_STD_VER <= 11
990+
&& (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
991+
|| __is_nothrow_swappable<__pointer_allocator>::value)
992+
&& (!__node_traits::propagate_on_container_swap::value
993+
|| __is_nothrow_swappable<__node_allocator>::value)
994+
#endif
995+
);
994996

995997
_LIBCPP_INLINE_VISIBILITY
996998
size_type max_bucket_count() const _NOEXCEPT
@@ -1118,38 +1120,6 @@ private:
11181120
_LIBCPP_INLINE_VISIBILITY
11191121
void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {}
11201122

1121-
template <class _Ap>
1122-
_LIBCPP_INLINE_VISIBILITY
1123-
static
1124-
void
1125-
__swap_alloc(_Ap& __x, _Ap& __y)
1126-
_NOEXCEPT_(
1127-
!allocator_traits<_Ap>::propagate_on_container_swap::value ||
1128-
__is_nothrow_swappable<_Ap>::value)
1129-
{
1130-
__swap_alloc(__x, __y,
1131-
integral_constant<bool,
1132-
allocator_traits<_Ap>::propagate_on_container_swap::value
1133-
>());
1134-
}
1135-
1136-
template <class _Ap>
1137-
_LIBCPP_INLINE_VISIBILITY
1138-
static
1139-
void
1140-
__swap_alloc(_Ap& __x, _Ap& __y, true_type)
1141-
_NOEXCEPT_(__is_nothrow_swappable<_Ap>::value)
1142-
{
1143-
using _VSTD::swap;
1144-
swap(__x, __y);
1145-
}
1146-
1147-
template <class _Ap>
1148-
_LIBCPP_INLINE_VISIBILITY
1149-
static
1150-
void
1151-
__swap_alloc(_Ap&, _Ap&, false_type) _NOEXCEPT {}
1152-
11531123
void __deallocate(__node_pointer __np) _NOEXCEPT;
11541124
__node_pointer __detach() _NOEXCEPT;
11551125

@@ -2382,22 +2352,24 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc>
23822352
void
23832353
__hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
23842354
_NOEXCEPT_(
2385-
(!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value ||
2386-
__is_nothrow_swappable<__pointer_allocator>::value) &&
2387-
(!__node_traits::propagate_on_container_swap::value ||
2388-
__is_nothrow_swappable<__node_allocator>::value) &&
2389-
__is_nothrow_swappable<hasher>::value &&
2390-
__is_nothrow_swappable<key_equal>::value)
2355+
__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
2356+
#if _LIBCPP_STD_VER <= 11
2357+
&& (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
2358+
|| __is_nothrow_swappable<__pointer_allocator>::value)
2359+
&& (!__node_traits::propagate_on_container_swap::value
2360+
|| __is_nothrow_swappable<__node_allocator>::value)
2361+
#endif
2362+
)
23912363
{
23922364
{
23932365
__node_pointer_pointer __npp = __bucket_list_.release();
23942366
__bucket_list_.reset(__u.__bucket_list_.release());
23952367
__u.__bucket_list_.reset(__npp);
23962368
}
23972369
_VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size());
2398-
__swap_alloc(__bucket_list_.get_deleter().__alloc(),
2370+
__swap_allocator(__bucket_list_.get_deleter().__alloc(),
23992371
__u.__bucket_list_.get_deleter().__alloc());
2400-
__swap_alloc(__node_alloc(), __u.__node_alloc());
2372+
__swap_allocator(__node_alloc(), __u.__node_alloc());
24012373
_VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_);
24022374
__p2_.swap(__u.__p2_);
24032375
__p3_.swap(__u.__p3_);

libcxx/include/__split_buffer

+1-20
Original file line numberDiff line numberDiff line change
@@ -156,25 +156,6 @@ private:
156156
_LIBCPP_INLINE_VISIBILITY
157157
void __move_assign_alloc(__split_buffer&, false_type) _NOEXCEPT
158158
{}
159-
160-
_LIBCPP_INLINE_VISIBILITY
161-
static void __swap_alloc(__alloc_rr& __x, __alloc_rr& __y)
162-
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value||
163-
__is_nothrow_swappable<__alloc_rr>::value)
164-
{__swap_alloc(__x, __y, integral_constant<bool,
165-
__alloc_traits::propagate_on_container_swap::value>());}
166-
167-
_LIBCPP_INLINE_VISIBILITY
168-
static void __swap_alloc(__alloc_rr& __x, __alloc_rr& __y, true_type)
169-
_NOEXCEPT_(__is_nothrow_swappable<__alloc_rr>::value)
170-
{
171-
using _VSTD::swap;
172-
swap(__x, __y);
173-
}
174-
175-
_LIBCPP_INLINE_VISIBILITY
176-
static void __swap_alloc(__alloc_rr&, __alloc_rr&, false_type) _NOEXCEPT
177-
{}
178159
};
179160

180161
template <class _Tp, class _Allocator>
@@ -431,7 +412,7 @@ __split_buffer<_Tp, _Allocator>::swap(__split_buffer& __x)
431412
_VSTD::swap(__begin_, __x.__begin_);
432413
_VSTD::swap(__end_, __x.__end_);
433414
_VSTD::swap(__end_cap(), __x.__end_cap());
434-
__swap_alloc(__alloc(), __x.__alloc());
415+
__swap_allocator(__alloc(), __x.__alloc());
435416
}
436417

437418
template <class _Tp, class _Allocator>

libcxx/include/__tree

+14-27
Original file line numberDiff line numberDiff line change
@@ -926,9 +926,12 @@ public:
926926

927927
void swap(__tree& __t)
928928
_NOEXCEPT_(
929-
__is_nothrow_swappable<value_compare>::value &&
930-
(!__node_traits::propagate_on_container_swap::value ||
931-
__is_nothrow_swappable<__node_allocator>::value));
929+
__is_nothrow_swappable<value_compare>::value
930+
#if _LIBCPP_STD_VER <= 11
931+
&& (!__node_traits::propagate_on_container_swap::value ||
932+
__is_nothrow_swappable<__node_allocator>::value)
933+
#endif
934+
);
932935

933936
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
934937
#ifndef _LIBCPP_HAS_NO_VARIADICS
@@ -1096,25 +1099,6 @@ private:
10961099
_LIBCPP_INLINE_VISIBILITY
10971100
void __move_assign_alloc(__tree& __t, false_type) _NOEXCEPT {}
10981101

1099-
_LIBCPP_INLINE_VISIBILITY
1100-
static void __swap_alloc(__node_allocator& __x, __node_allocator& __y)
1101-
_NOEXCEPT_(
1102-
!__node_traits::propagate_on_container_swap::value ||
1103-
__is_nothrow_swappable<__node_allocator>::value)
1104-
{__swap_alloc(__x, __y, integral_constant<bool,
1105-
__node_traits::propagate_on_container_swap::value>());}
1106-
_LIBCPP_INLINE_VISIBILITY
1107-
static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, true_type)
1108-
_NOEXCEPT_(__is_nothrow_swappable<__node_allocator>::value)
1109-
{
1110-
using _VSTD::swap;
1111-
swap(__x, __y);
1112-
}
1113-
_LIBCPP_INLINE_VISIBILITY
1114-
static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, false_type)
1115-
_NOEXCEPT
1116-
{}
1117-
11181102
__node_pointer __detach();
11191103
static __node_pointer __detach(__node_pointer);
11201104

@@ -1452,15 +1436,18 @@ __tree<_Tp, _Compare, _Allocator>::destroy(__node_pointer __nd) _NOEXCEPT
14521436
template <class _Tp, class _Compare, class _Allocator>
14531437
void
14541438
__tree<_Tp, _Compare, _Allocator>::swap(__tree& __t)
1455-
_NOEXCEPT_(
1456-
__is_nothrow_swappable<value_compare>::value &&
1457-
(!__node_traits::propagate_on_container_swap::value ||
1458-
__is_nothrow_swappable<__node_allocator>::value))
1439+
_NOEXCEPT_(
1440+
__is_nothrow_swappable<value_compare>::value
1441+
#if _LIBCPP_STD_VER <= 11
1442+
&& (!__node_traits::propagate_on_container_swap::value ||
1443+
__is_nothrow_swappable<__node_allocator>::value)
1444+
#endif
1445+
)
14591446
{
14601447
using _VSTD::swap;
14611448
swap(__begin_node_, __t.__begin_node_);
14621449
swap(__pair1_.first(), __t.__pair1_.first());
1463-
__swap_alloc(__node_alloc(), __t.__node_alloc());
1450+
__swap_allocator(__node_alloc(), __t.__node_alloc());
14641451
__pair3_.swap(__t.__pair3_);
14651452
if (size() == 0)
14661453
__begin_node() = __end_node();

libcxx/include/deque

+37-42
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ public:
124124
iterator erase(const_iterator p);
125125
iterator erase(const_iterator f, const_iterator l);
126126
void swap(deque& c)
127-
noexcept(!allocator_type::propagate_on_container_swap::value ||
128-
__is_nothrow_swappable<allocator_type>::value);
127+
noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17
129128
void clear() noexcept;
130129
};
131130
@@ -954,8 +953,12 @@ public:
954953

955954
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
956955
void swap(__deque_base& __c)
957-
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
958-
__is_nothrow_swappable<allocator_type>::value);
956+
#if _LIBCPP_STD_VER >= 14
957+
_NOEXCEPT;
958+
#else
959+
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
960+
__is_nothrow_swappable<allocator_type>::value);
961+
#endif
959962
protected:
960963
void clear() _NOEXCEPT;
961964

@@ -991,26 +994,6 @@ private:
991994
_LIBCPP_INLINE_VISIBILITY
992995
void __move_assign_alloc(__deque_base&, false_type) _NOEXCEPT
993996
{}
994-
995-
_LIBCPP_INLINE_VISIBILITY
996-
static void __swap_alloc(allocator_type& __x, allocator_type& __y)
997-
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
998-
__is_nothrow_swappable<allocator_type>::value)
999-
{__swap_alloc(__x, __y, integral_constant<bool,
1000-
__alloc_traits::propagate_on_container_swap::value>());}
1001-
1002-
_LIBCPP_INLINE_VISIBILITY
1003-
static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
1004-
_NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
1005-
{
1006-
using _VSTD::swap;
1007-
swap(__x, __y);
1008-
}
1009-
1010-
_LIBCPP_INLINE_VISIBILITY
1011-
static void __swap_alloc(allocator_type&, allocator_type&, false_type)
1012-
_NOEXCEPT
1013-
{}
1014997
};
1015998

1016999
template <class _Tp, class _Allocator>
@@ -1134,13 +1117,17 @@ __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_
11341117
template <class _Tp, class _Allocator>
11351118
void
11361119
__deque_base<_Tp, _Allocator>::swap(__deque_base& __c)
1137-
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value||
1138-
__is_nothrow_swappable<allocator_type>::value)
1120+
#if _LIBCPP_STD_VER >= 14
1121+
_NOEXCEPT
1122+
#else
1123+
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1124+
__is_nothrow_swappable<allocator_type>::value)
1125+
#endif
11391126
{
11401127
__map_.swap(__c.__map_);
11411128
_VSTD::swap(__start_, __c.__start_);
11421129
_VSTD::swap(size(), __c.size());
1143-
__swap_alloc(__alloc(), __c.__alloc());
1130+
__swap_allocator(__alloc(), __c.__alloc());
11441131
}
11451132

11461133
template <class _Tp, class _Allocator>
@@ -1342,8 +1329,12 @@ public:
13421329
iterator erase(const_iterator __f, const_iterator __l);
13431330

13441331
void swap(deque& __c)
1332+
#if _LIBCPP_STD_VER >= 14
1333+
_NOEXCEPT;
1334+
#else
13451335
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
13461336
__is_nothrow_swappable<allocator_type>::value);
1337+
#endif
13471338
void clear() _NOEXCEPT;
13481339

13491340
_LIBCPP_INLINE_VISIBILITY
@@ -2277,13 +2268,13 @@ deque<_Tp, _Allocator>::__add_front_capacity()
22772268
__buf(max<size_type>(2 * __base::__map_.capacity(), 1),
22782269
0, __base::__map_.__alloc());
22792270

2280-
typedef __allocator_destructor<_Allocator> _Dp;
2281-
unique_ptr<pointer, _Dp> __hold(
2282-
__alloc_traits::allocate(__a, __base::__block_size),
2283-
_Dp(__a, __base::__block_size));
2284-
__buf.push_back(__hold.get());
2285-
__hold.release();
2286-
2271+
typedef __allocator_destructor<_Allocator> _Dp;
2272+
unique_ptr<pointer, _Dp> __hold(
2273+
__alloc_traits::allocate(__a, __base::__block_size),
2274+
_Dp(__a, __base::__block_size));
2275+
__buf.push_back(__hold.get());
2276+
__hold.release();
2277+
22872278
for (typename __base::__map_pointer __i = __base::__map_.begin();
22882279
__i != __base::__map_.end(); ++__i)
22892280
__buf.push_back(*__i);
@@ -2420,12 +2411,12 @@ deque<_Tp, _Allocator>::__add_back_capacity()
24202411
__base::__map_.size(),
24212412
__base::__map_.__alloc());
24222413

2423-
typedef __allocator_destructor<_Allocator> _Dp;
2424-
unique_ptr<pointer, _Dp> __hold(
2425-
__alloc_traits::allocate(__a, __base::__block_size),
2426-
_Dp(__a, __base::__block_size));
2427-
__buf.push_back(__hold.get());
2428-
__hold.release();
2414+
typedef __allocator_destructor<_Allocator> _Dp;
2415+
unique_ptr<pointer, _Dp> __hold(
2416+
__alloc_traits::allocate(__a, __base::__block_size),
2417+
_Dp(__a, __base::__block_size));
2418+
__buf.push_back(__hold.get());
2419+
__hold.release();
24292420

24302421
for (typename __base::__map_pointer __i = __base::__map_.end();
24312422
__i != __base::__map_.begin();)
@@ -2793,8 +2784,12 @@ template <class _Tp, class _Allocator>
27932784
inline _LIBCPP_INLINE_VISIBILITY
27942785
void
27952786
deque<_Tp, _Allocator>::swap(deque& __c)
2796-
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2797-
__is_nothrow_swappable<allocator_type>::value)
2787+
#if _LIBCPP_STD_VER >= 14
2788+
_NOEXCEPT
2789+
#else
2790+
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2791+
__is_nothrow_swappable<allocator_type>::value)
2792+
#endif
27982793
{
27992794
__base::swap(__c);
28002795
}

0 commit comments

Comments
 (0)