From: Marc Glisse Date: Mon, 13 Oct 2014 10:00:27 +0000 (+0200) Subject: re PR libstdc++/61347 (std::distance(list.first(),list.end()) in O(1)) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2a5273835024d375fecd273fd066becab39d82af;p=gcc.git re PR libstdc++/61347 (std::distance(list.first(),list.end()) in O(1)) 2014-10-13 Marc Glisse PR libstdc++/61347 PR libstdc++/63345 * include/bits/list.tcc (_List_base::_M_clear()): Delay cast so it isn't done for the sentinel. * include/bits/stl_list.h (_List_base::_M_size): Move... (_List_base::_List_impl::_M_node): ... here. (_List_base::_M_get_size(), _List_base::_M_set_size(size_t), _List_base::_M_inc_size(size_t), _List_base::_M_dec_size(size_t), _List_base::_M_node_count): Adapt to the move. * 23_containers/list/requirements/dr438/assign_neg.cc: Update line number. * 23_containers/list/requirements/dr438/constructor_1_neg.cc: Likewise. * 23_containers/list/requirements/dr438/constructor_2_neg.cc: Likewise. * 23_containers/list/requirements/dr438/insert_neg.cc: Likewise. From-SVN: r216142 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 40931a37d52..508c9d391e9 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,20 @@ +2014-10-13 Marc Glisse + + PR libstdc++/61347 + PR libstdc++/63345 + * include/bits/list.tcc (_List_base::_M_clear()): Delay cast so it + isn't done for the sentinel. + * include/bits/stl_list.h (_List_base::_M_size): Move... + (_List_base::_List_impl::_M_node): ... here. + (_List_base::_M_get_size(), _List_base::_M_set_size(size_t), + _List_base::_M_inc_size(size_t), _List_base::_M_dec_size(size_t), + _List_base::_M_node_count): Adapt to the move. + * 23_containers/list/requirements/dr438/assign_neg.cc: Update + line number. + * 23_containers/list/requirements/dr438/constructor_1_neg.cc: Likewise. + * 23_containers/list/requirements/dr438/constructor_2_neg.cc: Likewise. + * 23_containers/list/requirements/dr438/insert_neg.cc: Likewise. + 2014-10-10 Jonathan Wakely * testsuite/Makefile.in: Regenerate. diff --git a/libstdc++-v3/include/bits/list.tcc b/libstdc++-v3/include/bits/list.tcc index f99ec54ca40..7b3ab86e22b 100644 --- a/libstdc++-v3/include/bits/list.tcc +++ b/libstdc++-v3/include/bits/list.tcc @@ -66,11 +66,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_clear() _GLIBCXX_NOEXCEPT { typedef _List_node<_Tp> _Node; - _Node* __cur = static_cast<_Node*>(_M_impl._M_node._M_next); + __detail::_List_node_base* __cur = _M_impl._M_node._M_next; while (__cur != &_M_impl._M_node) { - _Node* __tmp = __cur; - __cur = static_cast<_Node*>(__cur->_M_next); + _Node* __tmp = static_cast<_Node*>(__cur); + __cur = __tmp->_M_next; #if __cplusplus >= 201103L _M_get_Node_allocator().destroy(__tmp); #else diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h index 8e6567cfe67..5f66afdaa50 100644 --- a/libstdc++-v3/include/bits/stl_list.h +++ b/libstdc++-v3/include/bits/stl_list.h @@ -332,7 +332,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER struct _List_impl : public _Node_alloc_type { +#if _GLIBCXX_USE_CXX11_ABI + _List_node _M_node; +#else __detail::_List_node_base _M_node; +#endif _List_impl() : _Node_alloc_type(), _M_node() @@ -352,15 +356,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _List_impl _M_impl; #if _GLIBCXX_USE_CXX11_ABI - size_t _M_size; - - size_t _M_get_size() const { return _M_size; } + size_t _M_get_size() const { return _M_impl._M_node._M_data; } - void _M_set_size(size_t __n) { _M_size = __n; } + void _M_set_size(size_t __n) { _M_impl._M_node._M_data = __n; } - void _M_inc_size(size_t __n) { _M_size += __n; } + void _M_inc_size(size_t __n) { _M_impl._M_node._M_data += __n; } - void _M_dec_size(size_t __n) { _M_size -= __n; } + void _M_dec_size(size_t __n) { _M_impl._M_node._M_data -= __n; } size_t _M_distance(const __detail::_List_node_base* __first, @@ -368,7 +370,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { return _S_distance(__first, __last); } // return the stored size - size_t _M_node_count() const { return _M_size; } + size_t _M_node_count() const { return _M_impl._M_node._M_data; } #else // dummy implementations used when the size is not stored size_t _M_get_size() const { return 0; } diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/assign_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/assign_neg.cc index 183753dca5f..37d65b365ba 100644 --- a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/assign_neg.cc @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1728 } +// { dg-error "no matching" "" { target *-*-* } 1730 } #include diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc index e81ff98d43e..62483c82719 100644 --- a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_1_neg.cc @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1680 } +// { dg-error "no matching" "" { target *-*-* } 1682 } #include diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc index c98aa0f476b..39c7318846d 100644 --- a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/constructor_2_neg.cc @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1680 } +// { dg-error "no matching" "" { target *-*-* } 1682 } #include #include diff --git a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/insert_neg.cc b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/insert_neg.cc index 1397796132c..2dba620017e 100644 --- a/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/insert_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/list/requirements/dr438/insert_neg.cc @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1680 } +// { dg-error "no matching" "" { target *-*-* } 1682 } #include