Skip to content

Commit 8b0cd47

Browse files
committed
2018-05-18 François Dumont <[email protected]>
* include/bits/stl_tree.h (_Rb_tree_impl(_Rb_tree_impl&&, _Node_allocator&&)): New. (_Rb_tree(_Rb_tree&&, _Node_allocator&&, true_type)): New, use latter. (_Rb_tree(_Rb_tree&&, _Node_allocator&&, false_type)): New. (_Rb_tree(_Rb_tree&&, _Node_allocator&&)): Adapt, use latters. * include/debug/map.h (map(map&&, const_allocator_type&)): Add noexcept qualitication. * include/debug/multimap.h (multimap(multimap&&, const_allocator_type&)): Likewise. * include/debug/set.h (set(set&&, const_allocator_type&)): Likewise. * include/debug/multiset.h (multiset(multiset&&, const_allocator_type&)): Likewise. * testsuite/23_containers/map/cons/noexcept_default_construct.cc: Add checks. * testsuite/23_containers/map/cons/noexcept_move_construct.cc: Add checks. * testsuite/23_containers/multimap/cons/noexcept_default_construct.cc: Add checks. * testsuite/23_containers/multimap/cons/noexcept_move_construct.cc: Add checks. * testsuite/23_containers/multiset/cons/noexcept_default_construct.cc: Add checks. * testsuite/23_containers/multiset/cons/noexcept_move_construct.cc: Add checks. * testsuite/23_containers/set/cons/noexcept_default_construct.cc: Add checks. * testsuite/23_containers/set/cons/noexcept_move_construct.cc: Add checks. From-SVN: r260382
1 parent b46b715 commit 8b0cd47

File tree

14 files changed

+224
-25
lines changed

14 files changed

+224
-25
lines changed

libstdc++-v3/ChangeLog

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
2018-05-18 François Dumont <[email protected]>
2+
3+
* include/bits/stl_tree.h
4+
(_Rb_tree_impl(_Rb_tree_impl&&, _Node_allocator&&)): New.
5+
(_Rb_tree(_Rb_tree&&, _Node_allocator&&, true_type)): New, use latter.
6+
(_Rb_tree(_Rb_tree&&, _Node_allocator&&, false_type)): New.
7+
(_Rb_tree(_Rb_tree&&, _Node_allocator&&)): Adapt, use latters.
8+
* include/debug/map.h
9+
(map(map&&, const_allocator_type&)): Add noexcept qualitication.
10+
* include/debug/multimap.h
11+
(multimap(multimap&&, const_allocator_type&)): Likewise.
12+
* include/debug/set.h
13+
(set(set&&, const_allocator_type&)): Likewise.
14+
* include/debug/multiset.h
15+
(multiset(multiset&&, const_allocator_type&)): Likewise.
16+
* testsuite/23_containers/map/cons/noexcept_default_construct.cc:
17+
Add checks.
18+
* testsuite/23_containers/map/cons/noexcept_move_construct.cc:
19+
Add checks.
20+
* testsuite/23_containers/multimap/cons/noexcept_default_construct.cc:
21+
Add checks.
22+
* testsuite/23_containers/multimap/cons/noexcept_move_construct.cc:
23+
Add checks.
24+
* testsuite/23_containers/multiset/cons/noexcept_default_construct.cc:
25+
Add checks.
26+
* testsuite/23_containers/multiset/cons/noexcept_move_construct.cc:
27+
Add checks.
28+
* testsuite/23_containers/set/cons/noexcept_default_construct.cc:
29+
Add checks.
30+
* testsuite/23_containers/set/cons/noexcept_move_construct.cc:
31+
Add checks.
32+
133
2018-05-18 Jason Merrill <[email protected]>
234

335
* include/bits/stl_deque.h (_Deque_iterator): Constrain constructor

libstdc++-v3/include/bits/stl_tree.h

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
471471
struct _Reuse_or_alloc_node
472472
{
473473
_Reuse_or_alloc_node(_Rb_tree& __t)
474-
: _M_root(__t._M_root()), _M_nodes(__t._M_rightmost()), _M_t(__t)
474+
: _M_root(__t._M_root()), _M_nodes(__t._M_rightmost()), _M_t(__t)
475475
{
476476
if (_M_root)
477477
{
@@ -555,7 +555,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
555555
struct _Alloc_node
556556
{
557557
_Alloc_node(_Rb_tree& __t)
558-
: _M_t(__t) { }
558+
: _M_t(__t) { }
559559

560560
template<typename _Arg>
561561
_Link_type
@@ -715,6 +715,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
715715
#else
716716
_Rb_tree_impl(_Rb_tree_impl&&) = default;
717717

718+
_Rb_tree_impl(_Rb_tree_impl&& __x, _Node_allocator&& __a)
719+
: _Node_allocator(std::move(__a)),
720+
_Base_key_compare(std::move(__x)),
721+
_Rb_tree_header(std::move(__x))
722+
{ }
723+
718724
_Rb_tree_impl(const _Key_compare& __comp, _Node_allocator&& __a)
719725
: _Node_allocator(std::move(__a)), _Base_key_compare(__comp)
720726
{ }
@@ -958,7 +964,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
958964
: _Rb_tree(std::move(__x), _Node_allocator(__a))
959965
{ }
960966

961-
_Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a);
967+
private:
968+
_Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a, true_type)
969+
noexcept(is_nothrow_default_constructible<_Compare>::value)
970+
: _M_impl(std::move(__x._M_impl), std::move(__a))
971+
{ }
972+
973+
_Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a, false_type)
974+
: _M_impl(__x._M_impl._M_key_compare, std::move(__a))
975+
{
976+
if (__x._M_root() != nullptr)
977+
_M_move_data(__x, false_type{});
978+
}
979+
980+
public:
981+
_Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a)
982+
noexcept( noexcept(
983+
_Rb_tree(std::declval<_Rb_tree>(), std::declval<_Node_allocator>(),
984+
std::declval<typename _Alloc_traits::is_always_equal>())) )
985+
: _Rb_tree(std::move(__x), std::move(__a),
986+
typename _Alloc_traits::is_always_equal{})
987+
{ }
962988
#endif
963989

964990
~_Rb_tree() _GLIBCXX_NOEXCEPT
@@ -1358,22 +1384,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
13581384
private:
13591385
// Move elements from container with equal allocator.
13601386
void
1361-
_M_move_data(_Rb_tree& __x, std::true_type)
1387+
_M_move_data(_Rb_tree& __x, true_type)
13621388
{ _M_impl._M_move_data(__x._M_impl); }
13631389

13641390
// Move elements from container with possibly non-equal allocator,
13651391
// which might result in a copy not a move.
13661392
void
1367-
_M_move_data(_Rb_tree&, std::false_type);
1393+
_M_move_data(_Rb_tree&, false_type);
13681394

13691395
// Move assignment from container with equal allocator.
13701396
void
1371-
_M_move_assign(_Rb_tree&, std::true_type);
1397+
_M_move_assign(_Rb_tree&, true_type);
13721398

13731399
// Move assignment from container with possibly non-equal allocator,
13741400
// which might result in a copy not a move.
13751401
void
1376-
_M_move_assign(_Rb_tree&, std::false_type);
1402+
_M_move_assign(_Rb_tree&, false_type);
13771403
#endif
13781404

13791405
#if __cplusplus > 201402L
@@ -1599,25 +1625,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
15991625
{ __x.swap(__y); }
16001626

16011627
#if __cplusplus >= 201103L
1602-
template<typename _Key, typename _Val, typename _KeyOfValue,
1603-
typename _Compare, typename _Alloc>
1604-
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1605-
_Rb_tree(_Rb_tree&& __x, _Node_allocator&& __a)
1606-
: _M_impl(__x._M_impl._M_key_compare, std::move(__a))
1607-
{
1608-
using __eq = typename _Alloc_traits::is_always_equal;
1609-
if (__x._M_root() != nullptr)
1610-
_M_move_data(__x, __eq());
1611-
}
1612-
16131628
template<typename _Key, typename _Val, typename _KeyOfValue,
16141629
typename _Compare, typename _Alloc>
16151630
void
16161631
_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
1617-
_M_move_data(_Rb_tree& __x, std::false_type)
1632+
_M_move_data(_Rb_tree& __x, false_type)
16181633
{
16191634
if (_M_get_Node_allocator() == __x._M_get_Node_allocator())
1620-
_M_move_data(__x, std::true_type());
1635+
_M_move_data(__x, true_type());
16211636
else
16221637
{
16231638
_Alloc_node __an(*this);
@@ -1639,7 +1654,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
16391654
{
16401655
clear();
16411656
if (__x._M_root() != nullptr)
1642-
_M_move_data(__x, std::true_type());
1657+
_M_move_data(__x, true_type());
16431658
std::__alloc_on_move(_M_get_Node_allocator(),
16441659
__x._M_get_Node_allocator());
16451660
}

libstdc++-v3/include/debug/map.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ namespace __debug
105105
: _Base(__m, __a) { }
106106

107107
map(map&& __m, const allocator_type& __a)
108+
noexcept( noexcept(_Base(std::move(__m._M_base()), __a)) )
108109
: _Safe(std::move(__m._M_safe()), __a),
109110
_Base(std::move(__m._M_base()), __a) { }
110111

libstdc++-v3/include/debug/multimap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ namespace __debug
105105
: _Base(__m, __a) { }
106106

107107
multimap(multimap&& __m, const allocator_type& __a)
108+
noexcept( noexcept(_Base(std::move(__m._M_base()), __a)) )
108109
: _Safe(std::move(__m._M_safe()), __a),
109110
_Base(std::move(__m._M_base()), __a) { }
110111

libstdc++-v3/include/debug/multiset.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ namespace __debug
104104
: _Base(__m, __a) { }
105105

106106
multiset(multiset&& __m, const allocator_type& __a)
107+
noexcept( noexcept(_Base(std::move(__m._M_base()), __a)) )
107108
: _Safe(std::move(__m._M_safe()), __a),
108109
_Base(std::move(__m._M_base()), __a) { }
109110

libstdc++-v3/include/debug/set.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ namespace __debug
104104
: _Base(__x, __a) { }
105105

106106
set(set&& __x, const allocator_type& __a)
107+
noexcept( noexcept(_Base(std::move(__x._M_base()), __a)) )
107108
: _Safe(std::move(__x._M_safe()), __a),
108109
_Base(std::move(__x._M_base()), __a) { }
109110

libstdc++-v3/testsuite/23_containers/map/cons/noexcept_default_construct.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,19 @@ struct cmp
3030

3131
using mtype2 = std::map<int, int, cmp>;
3232
static_assert( !std::is_nothrow_default_constructible<mtype2>::value, "Error");
33+
34+
template<typename _Tp>
35+
struct not_noexcept_cons_alloc : std::allocator<_Tp>
36+
{
37+
not_noexcept_cons_alloc() /* noexcept */
38+
{ }
39+
40+
template<typename _Tp1>
41+
struct rebind
42+
{ typedef not_noexcept_cons_alloc<_Tp1> other; };
43+
};
44+
45+
using mtype3 = std::map<int, int, std::less<int>,
46+
not_noexcept_cons_alloc<std::pair<const int, int>>>;
47+
48+
static_assert(!std::is_nothrow_default_constructible<mtype3>::value, "Error");

libstdc++-v3/testsuite/23_containers/map/cons/noexcept_move_construct.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,25 @@
2323

2424
typedef std::map<int, int> mtype;
2525

26-
static_assert(std::is_nothrow_move_constructible<mtype>::value, "Error");
26+
static_assert( std::is_nothrow_move_constructible<mtype>::value,
27+
"noexcept move constructor" );
28+
static_assert( std::is_nothrow_constructible<mtype,
29+
mtype&&, const typename mtype::allocator_type&>::value,
30+
"noexcept move constructor with allocator" );
31+
32+
struct not_noexcept_less
33+
{
34+
not_noexcept_less() = default;
35+
not_noexcept_less(const not_noexcept_less&) /* noexcept */
36+
{ }
37+
38+
bool
39+
operator()(int l, int r) const
40+
{ return l < r; }
41+
};
42+
43+
typedef std::map<int, int, not_noexcept_less> emtype;
44+
45+
static_assert( !std::is_nothrow_constructible<emtype, emtype&&,
46+
const typename emtype::allocator_type&>::value,
47+
"except move constructor with allocator" );

libstdc++-v3/testsuite/23_containers/multimap/cons/noexcept_default_construct.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,19 @@ struct cmp
3030

3131
using mtype2 = std::multimap<int, int, cmp>;
3232
static_assert( !std::is_nothrow_default_constructible<mtype2>::value, "Error");
33+
34+
template<typename _Tp>
35+
struct not_noexcept_cons_alloc : std::allocator<_Tp>
36+
{
37+
not_noexcept_cons_alloc() /* noexcept */
38+
{ }
39+
40+
template<typename _Tp1>
41+
struct rebind
42+
{ typedef not_noexcept_cons_alloc<_Tp1> other; };
43+
};
44+
45+
using mtype3 = std::multimap<int, int, std::less<int>,
46+
not_noexcept_cons_alloc<std::pair<const int, int>>>;
47+
48+
static_assert(!std::is_nothrow_default_constructible<mtype3>::value, "Error");

libstdc++-v3/testsuite/23_containers/multimap/cons/noexcept_move_construct.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,25 @@
2323

2424
typedef std::multimap<int, int> mmtype;
2525

26-
static_assert(std::is_nothrow_move_constructible<mmtype>::value, "Error");
26+
static_assert( std::is_nothrow_move_constructible<mmtype>::value,
27+
"noexcept move constructor" );
28+
static_assert( std::is_nothrow_constructible<mmtype,
29+
mmtype&&, const typename mmtype::allocator_type&>::value,
30+
"noexcept move constructor with allocator" );
31+
32+
struct not_noexcept_less
33+
{
34+
not_noexcept_less() = default;
35+
not_noexcept_less(const not_noexcept_less&) /* noexcept */
36+
{ }
37+
38+
bool
39+
operator()(int l, int r) const
40+
{ return l < r; }
41+
};
42+
43+
typedef std::multimap<int, int, not_noexcept_less> emmtype;
44+
45+
static_assert( !std::is_nothrow_constructible<emmtype, emmtype&&,
46+
const typename emmtype::allocator_type&>::value,
47+
"except move constructor with allocator" );

libstdc++-v3/testsuite/23_containers/multiset/cons/noexcept_default_construct.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,19 @@ struct cmp
3030

3131
using stype2 = std::multiset<int, cmp>;
3232
static_assert( !std::is_nothrow_default_constructible<stype2>::value, "Error");
33+
34+
template<typename _Tp>
35+
struct not_noexcept_cons_alloc : std::allocator<_Tp>
36+
{
37+
not_noexcept_cons_alloc() /* noexcept */
38+
{ }
39+
40+
template<typename _Tp1>
41+
struct rebind
42+
{ typedef not_noexcept_cons_alloc<_Tp1> other; };
43+
};
44+
45+
using stype3 = std::multiset<int, std::less<int>,
46+
not_noexcept_cons_alloc<int>>;
47+
48+
static_assert(!std::is_nothrow_default_constructible<stype3>::value, "Error");

libstdc++-v3/testsuite/23_containers/multiset/cons/noexcept_move_construct.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,25 @@
2323

2424
typedef std::multiset<int> mstype;
2525

26-
static_assert(std::is_nothrow_move_constructible<mstype>::value, "Error");
26+
static_assert( std::is_nothrow_move_constructible<mstype>::value,
27+
"noexcept move constructor" );
28+
static_assert( std::is_nothrow_constructible<mstype,
29+
mstype&&, const typename mstype::allocator_type&>::value,
30+
"noexcept move constructor with allocator" );
31+
32+
struct not_noexcept_less
33+
{
34+
not_noexcept_less() = default;
35+
not_noexcept_less(const not_noexcept_less&) /* noexcept */
36+
{ }
37+
38+
bool
39+
operator()(int l, int r) const
40+
{ return l < r; }
41+
};
42+
43+
typedef std::multiset<int, not_noexcept_less> emstype;
44+
45+
static_assert( !std::is_nothrow_constructible<emstype, emstype&&,
46+
const typename emstype::allocator_type&>::value,
47+
"except move constructor with allocator" );

libstdc++-v3/testsuite/23_containers/set/cons/noexcept_default_construct.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,19 @@ struct cmp
3030

3131
using stype2 = std::set<int, cmp>;
3232
static_assert( !std::is_nothrow_default_constructible<stype2>::value, "Error");
33+
34+
template<typename _Tp>
35+
struct not_noexcept_cons_alloc : std::allocator<_Tp>
36+
{
37+
not_noexcept_cons_alloc() /* noexcept */
38+
{ }
39+
40+
template<typename _Tp1>
41+
struct rebind
42+
{ typedef not_noexcept_cons_alloc<_Tp1> other; };
43+
};
44+
45+
using stype3 = std::set<int, std::less<int>,
46+
not_noexcept_cons_alloc<int>>;
47+
48+
static_assert(!std::is_nothrow_default_constructible<stype3>::value, "Error");

libstdc++-v3/testsuite/23_containers/set/cons/noexcept_move_construct.cc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,25 @@
2323

2424
typedef std::set<int> stype;
2525

26-
static_assert(std::is_nothrow_move_constructible<stype>::value, "Error");
26+
static_assert( std::is_nothrow_move_constructible<stype>::value,
27+
"noexcept move constructor" );
28+
static_assert( std::is_nothrow_constructible<stype,
29+
stype&&, const typename stype::allocator_type&>::value,
30+
"noexcept move constructor with allocator" );
31+
32+
struct not_noexcept_less
33+
{
34+
not_noexcept_less() = default;
35+
not_noexcept_less(const not_noexcept_less&) /* noexcept */
36+
{ }
37+
38+
bool
39+
operator()(int l, int r) const
40+
{ return l < r; }
41+
};
42+
43+
typedef std::set<int, not_noexcept_less> estype;
44+
45+
static_assert( !std::is_nothrow_constructible<estype, estype&&,
46+
const typename estype::allocator_type&>::value,
47+
"except move constructor with allocator" );

0 commit comments

Comments
 (0)