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]

[llvm-gcc] Is it OK to backport this patch?


I would like to  add the attached patch to llvm-gcc. It is a backport
of part of http://gcc.gnu.org/ml/gcc-cvs/2007-10/msg00118.html. All
the files touched by the patch were still copyrighted under the GPL2
at the time the patch was committed to gcc trunk.

The part of the patch that I have ported allows the use of classes
with private copy constructors in parts of the STL. For example, with
the patch llvm-gcc now compiles

---------------------------------------------------
       #include <set>

       class A {
       public:
         A();
         private:
         A(const A&);
       };
       void B()
       {
         std::set<void *, A> foo;
       }
-------------------------------------------------

OK to commit the patch?

Cheers,
-- 
Rafael Avila de Espindola

Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047
Index: libstdc++-v3/include/bits/stl_list.h
===================================================================
--- libstdc++-v3/include/bits/stl_list.h	(revision 75131)
+++ libstdc++-v3/include/bits/stl_list.h	(working copy)
@@ -305,6 +305,10 @@
       {
 	_List_node_base _M_node;
 
+	_List_impl()
+	: _Node_alloc_type(), _M_node()
+	{ }
+
 	_List_impl(const _Node_alloc_type& __a)
 	: _Node_alloc_type(__a), _M_node()
 	{ }
@@ -339,6 +343,10 @@
       get_allocator() const
       { return allocator_type(_M_get_Node_allocator()); }
 
+      _List_base()
+      : _M_impl()
+      { _M_init(); }
+
       _List_base(const allocator_type& __a)
       : _M_impl(__a)
       { _M_init(); }
@@ -468,8 +476,15 @@
       /**
        *  @brief  Default constructor creates no elements.
        */
+      list()
+      : _Base() { }
+
+      /**
+       *  @brief  Creates a %list with no elements.
+       *  @param  a  An allocator object.
+       */
       explicit
-      list(const allocator_type& __a = allocator_type())
+      list(const allocator_type& __a)
       : _Base(__a) { }
 
       /**
Index: libstdc++-v3/include/bits/stl_map.h
===================================================================
--- libstdc++-v3/include/bits/stl_map.h	(revision 75131)
+++ libstdc++-v3/include/bits/stl_map.h	(working copy)
@@ -155,7 +155,7 @@
        *  @brief  Default constructor creates no elements.
        */
       map()
-      : _M_t(_Compare(), allocator_type()) { }
+      : _M_t() { }
 
       // for some reason this was made a separate function
       /**
@@ -186,7 +186,7 @@
        */
       template <typename _InputIterator>
         map(_InputIterator __first, _InputIterator __last)
-	: _M_t(_Compare(), allocator_type())
+	: _M_t()
         { _M_t._M_insert_unique(__first, __last); }
 
       /**
Index: libstdc++-v3/include/bits/stl_set.h
===================================================================
--- libstdc++-v3/include/bits/stl_set.h	(revision 75131)
+++ libstdc++-v3/include/bits/stl_set.h	(working copy)
@@ -138,7 +138,7 @@
       // allocation/deallocation
       ///  Default constructor creates no elements.
       set()
-      : _M_t(_Compare(), allocator_type()) {}
+      : _M_t() { }
 
       /**
        *  @brief  Default constructor creates no elements.
@@ -162,7 +162,7 @@
        */
       template<class _InputIterator>
         set(_InputIterator __first, _InputIterator __last)
-        : _M_t(_Compare(), allocator_type())
+        : _M_t()
         { _M_t._M_insert_unique(__first, __last); }
 
       /**
@@ -190,7 +190,7 @@
        *  The newly-created %set uses a copy of the allocation object used
        *  by @a x.
        */
-      set(const set<_Key,_Compare,_Alloc>& __x)
+      set(const set& __x)
       : _M_t(__x._M_t) { }
 
       /**
@@ -200,8 +200,8 @@
        *  All the elements of @a x are copied, but unlike the copy constructor,
        *  the allocator object is not copied.
        */
-      set<_Key,_Compare,_Alloc>&
-      operator=(const set<_Key, _Compare, _Alloc>& __x)
+      set&
+      operator=(const set& __x)
       {
 	_M_t = __x._M_t;
 	return *this;
@@ -283,7 +283,7 @@
        *  std::swap(s1,s2) will feed to this function.
        */
       void
-      swap(set<_Key,_Compare,_Alloc>& __x)
+      swap(set& __x)
       { _M_t.swap(__x._M_t); }
 
       // insert/erase
Index: libstdc++-v3/include/bits/stl_multimap.h
===================================================================
--- libstdc++-v3/include/bits/stl_multimap.h	(revision 75131)
+++ libstdc++-v3/include/bits/stl_multimap.h	(working copy)
@@ -152,7 +152,7 @@
        *  @brief  Default constructor creates no elements.
        */
       multimap()
-      : _M_t(_Compare(), allocator_type()) { }
+      : _M_t() { }
 
       // for some reason this was made a separate function
       /**
@@ -184,8 +184,8 @@
        */
       template <typename _InputIterator>
         multimap(_InputIterator __first, _InputIterator __last)
-	: _M_t(_Compare(), allocator_type())
-        { _M_t._M_insert_equal(__first, __last); }
+	: _M_t()
+        { _M_t._M_insert_unique(__first, __last); }
 
       /**
        *  @brief  Builds a %multimap from a range.
Index: libstdc++-v3/include/bits/stl_vector.h
===================================================================
--- libstdc++-v3/include/bits/stl_vector.h	(revision 75131)
+++ libstdc++-v3/include/bits/stl_vector.h	(working copy)
@@ -84,6 +84,11 @@
 	_Tp*           _M_start;
 	_Tp*           _M_finish;
 	_Tp*           _M_end_of_storage;
+
+	_Vector_impl()
+	: _Tp_alloc_type(), _M_start(0), _M_finish(0), _M_end_of_storage(0)
+	{ }
+
 	_Vector_impl(_Tp_alloc_type const& __a)
 	: _Tp_alloc_type(__a), _M_start(0), _M_finish(0), _M_end_of_storage(0)
 	{ }
@@ -104,6 +109,9 @@
       get_allocator() const
       { return allocator_type(_M_get_Tp_allocator()); }
 
+      _Vector_base()
+      : _M_impl() { }
+
       _Vector_base(const allocator_type& __a)
       : _M_impl(__a)
       { }
@@ -194,8 +202,15 @@
       /**
        *  @brief  Default constructor creates no elements.
        */
+      vector()
+      : _Base() { }
+
+      /**
+       *  @brief  Creates a %vector with no elements.
+       *  @param  a  An allocator object.
+       */
       explicit
-      vector(const allocator_type& __a = allocator_type())
+      vector(const allocator_type& __a)
       : _Base(__a)
       { }
 
Index: libstdc++-v3/include/bits/stl_deque.h
===================================================================
--- libstdc++-v3/include/bits/stl_deque.h	(revision 75131)
+++ libstdc++-v3/include/bits/stl_deque.h	(working copy)
@@ -380,6 +380,10 @@
       typedef _Deque_iterator<_Tp, _Tp&, _Tp*>             iterator;
       typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
 
+      _Deque_base()
+      : _M_impl()
+      { _M_initialize_map(0); }
+
       _Deque_base(const allocator_type& __a, size_t __num_elements)
       : _M_impl(__a)
       { _M_initialize_map(__num_elements); }
@@ -406,6 +410,11 @@
 	iterator _M_start;
 	iterator _M_finish;
 
+	_Deque_impl()
+	: _Tp_alloc_type(), _M_map(0), _M_map_size(0),
+	  _M_start(), _M_finish()
+	{ }
+
 	_Deque_impl(const _Tp_alloc_type& __a)
 	: _Tp_alloc_type(__a), _M_map(0), _M_map_size(0),
 	  _M_start(), _M_finish()
@@ -679,8 +688,15 @@
       /**
        *  @brief  Default constructor creates no elements.
        */
+      deque()
+      : _Base() { }
+
+      /**
+       *  @brief  Creates a %deque with no elements.
+       *  @param  a  An allocator object.
+       */
       explicit
-      deque(const allocator_type& __a = allocator_type())
+      deque(const allocator_type& __a)
       : _Base(__a, 0) {}
 
       /**
Index: libstdc++-v3/include/bits/stl_multiset.h
===================================================================
--- libstdc++-v3/include/bits/stl_multiset.h	(revision 75131)
+++ libstdc++-v3/include/bits/stl_multiset.h	(working copy)
@@ -134,7 +134,7 @@
        *  @brief  Default constructor creates no elements.
        */
       multiset()
-      : _M_t(_Compare(), allocator_type()) { }
+      : _M_t() { }
 
       explicit
       multiset(const _Compare& __comp,
@@ -152,7 +152,7 @@
        */
       template <class _InputIterator>
         multiset(_InputIterator __first, _InputIterator __last)
-	: _M_t(_Compare(), allocator_type())
+	: _M_t()
         { _M_t._M_insert_equal(__first, __last); }
 
       /**
@@ -180,7 +180,7 @@
        *  The newly-created %multiset uses a copy of the allocation object used
        *  by @a x.
        */
-      multiset(const multiset<_Key,_Compare,_Alloc>& __x)
+      multiset(const multiset& __x)
       : _M_t(__x._M_t) { }
 
       /**
@@ -190,8 +190,8 @@
        *  All the elements of @a x are copied, but unlike the copy constructor,
        *  the allocator object is not copied.
        */
-      multiset<_Key,_Compare,_Alloc>&
-      operator=(const multiset<_Key,_Compare,_Alloc>& __x)
+      multiset&
+      operator=(const multiset& __x)
       {
 	_M_t = __x._M_t;
 	return *this;
@@ -275,7 +275,7 @@
        *  std::swap(s1,s2) will feed to this function.
        */
       void
-      swap(multiset<_Key, _Compare, _Alloc>& __x)
+      swap(multiset& __x)
       { _M_t.swap(__x._M_t); }
 
       // insert/erase
Index: libstdc++-v3/include/bits/stl_bvector.h
===================================================================
--- libstdc++-v3/include/bits/stl_bvector.h	(revision 75131)
+++ libstdc++-v3/include/bits/stl_bvector.h	(working copy)
@@ -385,6 +385,11 @@
 	_Bit_iterator 	_M_start;
 	_Bit_iterator 	_M_finish;
 	_Bit_type* 	_M_end_of_storage;
+
+	_Bvector_impl()
+	: _Bit_alloc_type(), _M_start(), _M_finish(), _M_end_of_storage(0)
+	{ }
+ 
 	_Bvector_impl(const _Bit_alloc_type& __a)
 	: _Bit_alloc_type(__a), _M_start(), _M_finish(), _M_end_of_storage(0)
 	{ }
@@ -405,7 +410,11 @@
       get_allocator() const
       { return allocator_type(_M_get_Bit_allocator()); }
 
-      _Bvector_base(const allocator_type& __a) : _M_impl(__a) { }
+      _Bvector_base()
+      : _M_impl() { }
+      
+      _Bvector_base(const allocator_type& __a)
+      : _M_impl(__a) { }
 
       ~_Bvector_base()
       { this->_M_deallocate(); }
@@ -480,8 +489,11 @@
     using _Base::_M_get_Bit_allocator;
 
   public:
+    vector()
+    : _Base() { }
+
     explicit
-    vector(const allocator_type& __a = allocator_type())
+    vector(const allocator_type& __a)
     : _Base(__a) { }
 
     explicit
@@ -678,7 +690,7 @@
     }
 
     void
-    swap(vector<bool, _Alloc>& __x)
+    swap(vector& __x)
     {
       std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
       std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
Index: libstdc++-v3/include/bits/stl_tree.h
===================================================================
--- libstdc++-v3/include/bits/stl_tree.h	(revision 75131)
+++ libstdc++-v3/include/bits/stl_tree.h	(working copy)
@@ -410,10 +410,19 @@
 	  _Rb_tree_node_base 	_M_header;
 	  size_type 		_M_node_count; // Keeps track of size of tree.
 
-	  _Rb_tree_impl(const _Node_allocator& __a = _Node_allocator(),
-			const _Key_compare& __comp = _Key_compare())
-	  : _Node_allocator(__a), _M_key_compare(__comp), _M_header(), 
+	  _Rb_tree_impl()
+	  : _Node_allocator(), _M_key_compare(), _M_header(),
 	    _M_node_count(0)
+	  { _M_initialize(); }
+
+	  _Rb_tree_impl(const _Key_compare& __comp, const _Node_allocator& __a)
+	  : _Node_allocator(__a), _M_key_compare(__comp), _M_header(),
+	    _M_node_count(0)
+	  { _M_initialize(); }
+
+	private:
+	  void
+	  _M_initialize()
 	  {
 	    this->_M_header._M_color = _S_red;
 	    this->_M_header._M_parent = 0;
@@ -431,11 +440,20 @@
 	  _Rb_tree_node_base 	_M_header;
 	  size_type 		_M_node_count; // Keeps track of size of tree.
 
-	  _Rb_tree_impl(const _Node_allocator& __a = _Node_allocator(),
-			const _Key_compare& __comp = _Key_compare())
+	  _Rb_tree_impl()
+	  : _Node_allocator(), _M_key_compare(), _M_header(),
+	    _M_node_count(0)
+	  { _M_initialize(); }
+
+	  _Rb_tree_impl(const _Key_compare& __comp, const _Node_allocator& __a)
 	  : _Node_allocator(__a), _M_key_compare(__comp), _M_header(),
 	    _M_node_count(0)
-	  { 
+	  { _M_initialize(); }
+
+	private:
+	  void
+	  _M_initialize()
+	  {
 	    this->_M_header._M_color = _S_red;
 	    this->_M_header._M_parent = 0;
 	    this->_M_header._M_left = &this->_M_header;
@@ -568,16 +586,13 @@
       _Rb_tree()
       { }
 
-      _Rb_tree(const _Compare& __comp)
-      : _M_impl(allocator_type(), __comp)
+      _Rb_tree(const _Compare& __comp,
+	       const allocator_type& __a = allocator_type())
+      : _M_impl(__comp, __a)
       { }
 
-      _Rb_tree(const _Compare& __comp, const allocator_type& __a)
-      : _M_impl(__a, __comp)
-      { }
-
-      _Rb_tree(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x)
-      : _M_impl(__x._M_get_Node_allocator(), __x._M_impl._M_key_compare)
+      _Rb_tree(const _Rb_tree& __x)
+      : _M_impl(__x._M_impl._M_key_compare, __x._M_get_Node_allocator())
       {
 	if (__x._M_root() != 0)
 	  {
@@ -591,8 +606,8 @@
       ~_Rb_tree()
       { _M_erase(_M_begin()); }
 
-      _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&
-      operator=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x);
+      _Rb_tree&
+      operator=(const _Rb_tree& __x);
 
       // Accessors.
       _Compare
@@ -653,7 +668,7 @@
       { return get_allocator().max_size(); }
 
       void
-      swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __t);
+      swap(_Rb_tree& __t);
 
       // Insert/erase.
       pair<iterator, bool>

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