diff mbox

Remove unordered containers iterators default initialization

Message ID 5293BAF5.7070709@gmail.com
State New
Headers show

Commit Message

François Dumont Nov. 25, 2013, 9:02 p.m. UTC
Hi

     Following N3644 discussion thread here is a patch proposal to 
remove default zero-initialization of unordered containers iterator. I 
also took the time to remove default zero-init of nodes _M_nxt pointer.

2013-11-25  François Dumont  <fdumont@gcc.gnu.org>

     * include/bits/hashtable_policy.h (_Hash_node_base): Default
     default constructor.
     (_Node_iterator): Likewise.
     (_Node_const_iterator): Likewise.
     * include/bits/hashtable.h: Adapt.

Tested under Linux x86_64.

Ok to commit ?

François

Comments

Christopher Jefferson Nov. 25, 2013, 11:09 p.m. UTC | #1
On 25 November 2013 21:02, François Dumont <frs.dumont@gmail.com> wrote:
>
> Hi
>
>     Following N3644 discussion thread here is a patch proposal to remove default zero-initialization of unordered containers iterator. I also took the time to remove default zero-init of nodes _M_nxt pointer.
>
> 2013-11-25  François Dumont  <fdumont@gcc.gnu.org>
>
>     * include/bits/hashtable_policy.h (_Hash_node_base): Default
>     default constructor.
>     (_Node_iterator): Likewise.
>     (_Node_const_iterator): Likewise.
>     * include/bits/hashtable.h: Adapt.
>
> Tested under Linux x86_64.
>
> Ok to commit ?
>
I just want to check exactly what is going on here, please correct me if I
am wrong.

Before N3644 there was (I believe) no guarantee we either default or value
constructing iterators lead to a default state.

Therefore, we were previously providing more functionality than the
standard required, which you are now removing. Are we sure we want to
remove that extra functionality?

Chris
diff mbox

Patch

Index: include/bits/hashtable_policy.h
===================================================================
--- include/bits/hashtable_policy.h	(revision 205288)
+++ include/bits/hashtable_policy.h	(working copy)
@@ -230,7 +230,7 @@ 
   {
     _Hash_node_base* _M_nxt;
 
-    _Hash_node_base() noexcept : _M_nxt() { }
+    _Hash_node_base() = default;
 
     _Hash_node_base(_Hash_node_base* __next) noexcept : _M_nxt(__next) { }
   };
@@ -306,6 +306,7 @@ 
 
       __node_type*  _M_cur;
 
+      _Node_iterator_base() = default;
       _Node_iterator_base(__node_type* __p) noexcept
       : _M_cur(__p) { }
 
@@ -348,8 +349,7 @@ 
       using reference = typename std::conditional<__constant_iterators,
 						  const _Value&, _Value&>::type;
 
-      _Node_iterator() noexcept
-      : __base_type(0) { }
+      _Node_iterator() = default;
 
       explicit
       _Node_iterator(__node_type* __p) noexcept
@@ -396,8 +396,7 @@ 
       typedef const _Value*				pointer;
       typedef const _Value&				reference;
 
-      _Node_const_iterator() noexcept
-      : __base_type(0) { }
+      _Node_const_iterator() = default;
 
       explicit
       _Node_const_iterator(__node_type* __p) noexcept
Index: include/bits/hashtable.h
===================================================================
--- include/bits/hashtable.h	(revision 205288)
+++ include/bits/hashtable.h	(working copy)
@@ -788,6 +788,7 @@ 
       __map_base(),
       __rehash_base(),
       __hashtable_alloc(__node_alloc_type(__a)),
+      _M_before_begin(nullptr),
       _M_element_count(0),
       _M_rehash_policy()
     {
@@ -811,6 +812,7 @@ 
 	__map_base(),
 	__rehash_base(),
 	__hashtable_alloc(__node_alloc_type(__a)),
+	_M_before_begin(nullptr),
 	_M_element_count(0),
 	_M_rehash_policy()
       {
@@ -952,6 +954,7 @@ 
 	    // _M_before_begin.
 	    __node_type* __ht_n = __ht._M_begin();
 	    __node_type* __this_n = __node_gen(__ht_n);
+	    __this_n->_M_nxt = nullptr;
 	    this->_M_copy_code(__this_n, __ht_n);
 	    _M_before_begin._M_nxt = __this_n;
 	    _M_buckets[_M_bucket_index(__this_n)] = &_M_before_begin;
@@ -961,6 +964,7 @@ 
 	    for (__ht_n = __ht_n->_M_next(); __ht_n; __ht_n = __ht_n->_M_next())
 	      {
 		__this_n = __node_gen(__ht_n);
+		__this_n->_M_nxt = nullptr;
 		__prev_n->_M_nxt = __this_n;
 		this->_M_copy_code(__this_n, __ht_n);
 		size_type __bkt = _M_bucket_index(__this_n);
@@ -1092,6 +1096,7 @@ 
 	__node_alloc_traits::_S_select_on_copy(__ht._M_node_allocator())),
       _M_buckets(),
       _M_bucket_count(__ht._M_bucket_count),
+      _M_before_begin(nullptr),
       _M_element_count(__ht._M_element_count),
       _M_rehash_policy(__ht._M_rehash_policy)
     {
@@ -1137,6 +1142,7 @@ 
       __hashtable_alloc(__node_alloc_type(__a)),
       _M_buckets(),
       _M_bucket_count(__ht._M_bucket_count),
+      _M_before_begin(nullptr),
       _M_element_count(__ht._M_element_count),
       _M_rehash_policy(__ht._M_rehash_policy)
     {
@@ -1158,6 +1164,7 @@ 
       __hashtable_alloc(__node_alloc_type(__a)),
       _M_buckets(),
       _M_bucket_count(__ht._M_bucket_count),
+      _M_before_begin(nullptr),
       _M_element_count(__ht._M_element_count),
       _M_rehash_policy(__ht._M_rehash_policy)
     {