This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] More small tweaks to forward_list


Hi,

tested x86_64-linux, committed to mainline.

Paolo.

////////////////////
2008-10-15  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/bits/forward_list.h: Remove pointless const qualifiers in
	const_casts.
	* include/bits/forward_list.tcc: Likewise.

	* include/bits/forward_list.h (forward_list<>::pointer,
	const_pointer, reference, const_reference): Fix, use _Tp_alloc_type.
	* testsuite/23_containers/forward_list/requirements/
	explicit_instantiation/1.cc: New.
	* testsuite/23_containers/forward_list/requirements/
	explicit_instantiation/1.cc: Likewise.

Index: include/bits/forward_list.h
===================================================================
*** include/bits/forward_list.h	(revision 141151)
--- include/bits/forward_list.h	(working copy)
***************
*** 31,38 ****
   *  This is a Standard C++ Library header.
   */
  
! #ifndef _GLIBCXX_FORWARD_LIST_H
! #define _GLIBCXX_FORWARD_LIST_H 1
  
  #pragma GCC system_header
  
--- 31,38 ----
   *  This is a Standard C++ Library header.
   */
  
! #ifndef _FORWARD_LIST_H
! #define _FORWARD_LIST_H 1
  
  #pragma GCC system_header
  
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 282,287 ****
--- 282,289 ----
        typedef typename _Alloc::template rebind<_Fwd_list_node<_Tp>>::other
          _Node_alloc_type;
  
+       typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type;
+ 
        struct _Fwd_list_impl 
        : public _Node_alloc_type
        {
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 300,306 ****
        _Fwd_list_impl _M_impl;
  
      public:
-       typedef _Alloc                          allocator_type;
        typedef _Fwd_list_iterator<_Tp>         iterator;
        typedef _Fwd_list_const_iterator<_Tp>   const_iterator;
  
--- 302,307 ----
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 314,328 ****
        _M_get_Node_allocator() const
        { return *static_cast<const _Node_alloc_type*>(&this->_M_impl); }
  
-       allocator_type
-       get_allocator() const
-       { return this->_M_get_Node_allocator(); }
- 
        _Fwd_list_base()
        : _M_impl()
        { this->_M_impl._M_head._M_next = 0; }
  
!       _Fwd_list_base(const allocator_type& __a)
        : _M_impl(__a)
        { this->_M_impl._M_head._M_next = 0; }
  
--- 315,325 ----
        _M_get_Node_allocator() const
        { return *static_cast<const _Node_alloc_type*>(&this->_M_impl); }
  
        _Fwd_list_base()
        : _M_impl()
        { this->_M_impl._M_head._M_next = 0; }
  
!       _Fwd_list_base(const _Alloc& __a)
        : _M_impl(__a)
        { this->_M_impl._M_head._M_next = 0; }
  
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 371,377 ****
          _M_insert_after(const_iterator __pos, _Args&&... __args)
          {
            _Fwd_list_node_base* __to
!             = const_cast<_Fwd_list_node_base* const>(__pos._M_node);
            _Node* __thing = _M_create_node(std::forward<_Args>(__args)...);
            __thing->_M_next = __to->_M_next;
            __to->_M_next = __thing;
--- 368,374 ----
          _M_insert_after(const_iterator __pos, _Args&&... __args)
          {
            _Fwd_list_node_base* __to
!             = const_cast<_Fwd_list_node_base*>(__pos._M_node);
            _Node* __thing = _M_create_node(std::forward<_Args>(__args)...);
            __thing->_M_next = __to->_M_next;
            __to->_M_next = __thing;
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 425,445 ****
      class forward_list : private _Fwd_list_base<_Tp, _Alloc>
      {
      private:
!       typedef _Fwd_list_base<_Tp, _Alloc>       _Base;
!       typedef _Fwd_list_node<_Tp>               _Node;
  
      public:
        // types:
!       typedef typename _Alloc::reference        reference;
!       typedef typename _Alloc::const_reference  const_reference;
!       typedef _Fwd_list_iterator<_Tp>           iterator;
!       typedef _Fwd_list_const_iterator<_Tp>     const_iterator;
!       typedef std::size_t                       size_type;
!       typedef std::ptrdiff_t                    difference_type;
!       typedef _Tp                               value_type;
!       typedef typename _Base::allocator_type    allocator_type;
!       typedef typename _Alloc::pointer          pointer;
!       typedef typename _Alloc::const_pointer    const_pointer;
  
        // 23.2.3.1 construct/copy/destroy:
  
--- 422,443 ----
      class forward_list : private _Fwd_list_base<_Tp, _Alloc>
      {
      private:
!       typedef _Fwd_list_base<_Tp, _Alloc>                  _Base;
!       typedef _Fwd_list_node<_Tp>                          _Node;
!       typedef typename _Base::_Tp_alloc_type               _Tp_alloc_type;
  
      public:
        // types:
!       typedef _Tp                                          value_type;
!       typedef typename _Tp_alloc_type::pointer             pointer;
!       typedef typename _Tp_alloc_type::const_pointer       const_pointer;
!       typedef typename _Tp_alloc_type::reference           reference;
!       typedef typename _Tp_alloc_type::const_reference     const_reference;
!       typedef _Fwd_list_iterator<_Tp>                      iterator;
!       typedef _Fwd_list_const_iterator<_Tp>                const_iterator;
!       typedef std::size_t                                  size_type;
!       typedef std::ptrdiff_t                               difference_type;
!       typedef _Alloc                                       allocator_type;
  
        // 23.2.3.1 construct/copy/destroy:
  
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 647,653 ****
        /// Get a copy of the memory allocation object.
        allocator_type
        get_allocator() const
!       { return _Base::get_allocator(); }
  
        // 23.2.3.2 iterators:
  
--- 645,651 ----
        /// Get a copy of the memory allocation object.
        allocator_type
        get_allocator() const
!       { return this->_M_get_Node_allocator(); }
  
        // 23.2.3.2 iterators:
  
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 858,864 ****
        insert_after(const_iterator __pos, const _Tp& __val)
        {
          _Fwd_list_node_base* __to
!           = const_cast<_Fwd_list_node_base* const>(__pos._M_node);
          _Node* __thing = _M_create_node(__val);
          __thing->_M_next = __to->_M_next;
          __to->_M_next = __thing;
--- 856,862 ----
        insert_after(const_iterator __pos, const _Tp& __val)
        {
          _Fwd_list_node_base* __to
! 	  = const_cast<_Fwd_list_node_base*>(__pos._M_node);
          _Node* __thing = _M_create_node(__val);
          __thing->_M_next = __to->_M_next;
          __to->_M_next = __thing;
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 872,878 ****
        insert_after(const_iterator __pos, _Tp&& __val)
        {
          _Fwd_list_node_base* __to
!           = const_cast<_Fwd_list_node_base* const>(__pos._M_node);
          _Node* __thing = _M_create_node(std::move(__val));
          __thing->_M_next = __to->_M_next;
          __to->_M_next = __thing;
--- 870,876 ----
        insert_after(const_iterator __pos, _Tp&& __val)
        {
          _Fwd_list_node_base* __to
!           = const_cast<_Fwd_list_node_base*>(__pos._M_node);
          _Node* __thing = _M_create_node(std::move(__val));
          __thing->_M_next = __to->_M_next;
          __to->_M_next = __thing;
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 950,956 ****
        erase_after(const_iterator __pos)
        {
          _Fwd_list_node_base* __tmp
!           = const_cast<_Fwd_list_node_base* const>(__pos._M_node);
          if (__tmp)
            return iterator(_Base::_M_erase_after(__tmp));
          else
--- 948,954 ----
        erase_after(const_iterator __pos)
        {
          _Fwd_list_node_base* __tmp
!           = const_cast<_Fwd_list_node_base*>(__pos._M_node);
          if (__tmp)
            return iterator(_Base::_M_erase_after(__tmp));
          else
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 980,986 ****
        erase_after(const_iterator __pos, iterator __last)
        {
          _Fwd_list_node_base* __tmp
!           = const_cast<_Fwd_list_node_base* const>(__pos._M_node);
          return iterator(_M_erase_after(__tmp, __last._M_node));
        }
  
--- 978,984 ----
        erase_after(const_iterator __pos, iterator __last)
        {
          _Fwd_list_node_base* __tmp
!           = const_cast<_Fwd_list_node_base*>(__pos._M_node);
          return iterator(_M_erase_after(__tmp, __last._M_node));
        }
  
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 1060,1068 ****
          if (!__list.empty() && &__list != this)
            {
              _Fwd_list_node_base* __tmp
!               = const_cast<_Fwd_list_node_base* const>(__pos._M_node);
              const_iterator __before = __list.cbefore_begin();
!             __tmp->_M_transfer_after(const_cast<_Fwd_list_node_base* const>
  				     (__before._M_node));
            }
        }
--- 1058,1066 ----
          if (!__list.empty() && &__list != this)
            {
              _Fwd_list_node_base* __tmp
!               = const_cast<_Fwd_list_node_base*>(__pos._M_node);
              const_iterator __before = __list.cbefore_begin();
!             __tmp->_M_transfer_after(const_cast<_Fwd_list_node_base*>
  				     (__before._M_node));
            }
        }
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 1100,1109 ****
                     const_iterator __before, const_iterator __last)
        {
          _Fwd_list_node_base* __tmp
!           = const_cast<_Fwd_list_node_base* const>(__pos._M_node);
!         __tmp->_M_transfer_after(const_cast<_Fwd_list_node_base* const>
  				 (__before._M_node),
! 				 const_cast<_Fwd_list_node_base* const>
  				 (__last._M_node));
        }
  
--- 1098,1107 ----
                     const_iterator __before, const_iterator __last)
        {
          _Fwd_list_node_base* __tmp
!           = const_cast<_Fwd_list_node_base*>(__pos._M_node);
!         __tmp->_M_transfer_after(const_cast<_Fwd_list_node_base*>
  				 (__before._M_node),
! 				 const_cast<_Fwd_list_node_base*>
  				 (__last._M_node));
        }
  
*************** _GLIBCXX_END_NAMESPACE // namespace std
*** 1335,1338 ****
  
  #endif // __GXX_EXPERIMENTAL_CXX0X__
  
! #endif // _GLIBCXX_FORWARD_LIST_H
--- 1333,1336 ----
  
  #endif // __GXX_EXPERIMENTAL_CXX0X__
  
! #endif // _FORWARD_LIST_H
Index: include/bits/forward_list.tcc
===================================================================
*** include/bits/forward_list.tcc	(revision 141146)
--- include/bits/forward_list.tcc	(working copy)
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 299,305 ****
  		 size_type __n, const _Tp& __val)
      {
        _Fwd_list_node_base* __to
! 	= const_cast<_Fwd_list_node_base* const>(__pos._M_node);
        _Fwd_list_node_base* __keep = __to->_M_next;
        for (size_type __i = 0; __i < __n; ++__i)
  	{
--- 299,305 ----
  		 size_type __n, const _Tp& __val)
      {
        _Fwd_list_node_base* __to
! 	= const_cast<_Fwd_list_node_base*>(__pos._M_node);
        _Fwd_list_node_base* __keep = __to->_M_next;
        for (size_type __i = 0; __i < __n; ++__i)
  	{
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 317,323 ****
  		   _InputIterator __first, _InputIterator __last)
        {
  	_Fwd_list_node_base* __to
! 	  = const_cast<_Fwd_list_node_base* const>(__pos._M_node);
  	_Fwd_list_node_base* __keep = __to->_M_next;
  	_InputIterator __curr = __first;
  	while (__curr != __last)
--- 317,323 ----
  		   _InputIterator __first, _InputIterator __last)
        {
  	_Fwd_list_node_base* __to
! 	  = const_cast<_Fwd_list_node_base*>(__pos._M_node);
  	_Fwd_list_node_base* __keep = __to->_M_next;
  	_InputIterator __curr = __first;
  	while (__curr != __last)
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 335,341 ****
      insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
      {
        _Fwd_list_node_base* __to
! 	= const_cast<_Fwd_list_node_base* const>(__pos._M_node);
        _Fwd_list_node_base* __keep = __to->_M_next;
        const _Tp* __item = __il.begin();
        while (__item != __il.end())
--- 335,341 ----
      insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
      {
        _Fwd_list_node_base* __to
! 	= const_cast<_Fwd_list_node_base*>(__pos._M_node);
        _Fwd_list_node_base* __keep = __to->_M_next;
        const _Tp* __item = __il.begin();
        while (__item != __il.end())
*************** _GLIBCXX_BEGIN_NAMESPACE(std)
*** 431,437 ****
          while (++__next != __last)
  	{
  	  if (__binary_pred(*__first, *__next))
!               erase_after(__first);
  	  else
  	    __first = __next;
  	  __next = __first;
--- 431,437 ----
          while (++__next != __last)
  	{
  	  if (__binary_pred(*__first, *__next))
! 	    erase_after(__first);
  	  else
  	    __first = __next;
  	  __next = __first;
Index: testsuite/23_containers/forward_list/requirements/explicit_instantiation/1.cc
===================================================================
*** testsuite/23_containers/forward_list/requirements/explicit_instantiation/1.cc	(revision 0)
--- testsuite/23_containers/forward_list/requirements/explicit_instantiation/1.cc	(revision 0)
***************
*** 0 ****
--- 1,36 ----
+ // { dg-options "-std=gnu++0x" }
+ 
+ // Copyright (C) 2008 Free Software Foundation, Inc.
+ //
+ // This file is part of the GNU ISO C++ Library.  This library is free
+ // software; you can redistribute it and/or modify it under the
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+ 
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ // GNU General Public License for more details.
+ 
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING.  If not, write to the Free
+ // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ // USA.
+ 
+ // As a special exception, you may use this file as part of a free software
+ // library without restriction.  Specifically, if other files instantiate
+ // templates or use macros or inline functions from this file, or you compile
+ // this file and link it with other files to produce an executable, this
+ // file does not by itself cause the resulting executable to be covered by
+ // the GNU General Public License.  This exception does not however
+ // invalidate any other reasons why the executable file might be covered by
+ // the GNU General Public License.
+ 
+ // This file tests explicit instantiation of library containers
+ 
+ #include <forward_list>
+ 
+ // { dg-do compile }
+ 
+ template class std::forward_list<int>;
Index: testsuite/23_containers/forward_list/requirements/explicit_instantiation/3.cc
===================================================================
*** testsuite/23_containers/forward_list/requirements/explicit_instantiation/3.cc	(revision 0)
--- testsuite/23_containers/forward_list/requirements/explicit_instantiation/3.cc	(revision 0)
***************
*** 0 ****
--- 1,37 ----
+ // { dg-options "-std=gnu++0x" }
+ 
+ // Copyright (C) 2008 Free Software Foundation, Inc.
+ //
+ // This file is part of the GNU ISO C++ Library.  This library is free
+ // software; you can redistribute it and/or modify it under the
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+ 
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ // GNU General Public License for more details.
+ 
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING.  If not, write to the Free
+ // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ // USA.
+ 
+ // As a special exception, you may use this file as part of a free software
+ // library without restriction.  Specifically, if other files instantiate
+ // templates or use macros or inline functions from this file, or you compile
+ // this file and link it with other files to produce an executable, this
+ // file does not by itself cause the resulting executable to be covered by
+ // the GNU General Public License.  This exception does not however
+ // invalidate any other reasons why the executable file might be covered by
+ // the GNU General Public License.
+ 
+ // This file tests explicit instantiation of library containers
+ 
+ #include <forward_list>
+ 
+ // { dg-do compile }
+ 
+ // libstdc++/21770
+ template class std::forward_list<int, std::allocator<char> >;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]