https://gcc.gnu.org/g:f1309dbc7c281dc9fd70db8ec6e8cb804b2089fc

commit r15-6276-gf1309dbc7c281dc9fd70db8ec6e8cb804b2089fc
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Thu Dec 12 20:42:19 2024 +0000

    libstdc++: Initialize all members of hashtable local iterators
    
    Currently the _M_bucket members are left uninitialized for
    default-initialized local iterators, and then copy construction copies
    indeterminate values. We should just ensure they're initialized on
    construction.
    
    Setting them to zero makes default-initialization consistent with
    value-initialization and avoids indeterminate values.
    
    For the _Local_iterator_base<..., false> specialization we preserve the
    existing behaviour of setting _M_bucket_count to -1 in the default
    constructor, as a sentinel value to indicate there's no hash object
    present.
    
    libstdc++-v3/ChangeLog:
    
            * include/bits/hashtable_policy.h (_Local_iterator_base): Use
            default member-initializers.

Diff:
---
 libstdc++-v3/include/bits/hashtable_policy.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libstdc++-v3/include/bits/hashtable_policy.h 
b/libstdc++-v3/include/bits/hashtable_policy.h
index b7788eb5bd78..6f46a5796ba3 100644
--- a/libstdc++-v3/include/bits/hashtable_policy.h
+++ b/libstdc++-v3/include/bits/hashtable_policy.h
@@ -1156,8 +1156,8 @@ namespace __detail
          }
       }
 
-      size_t _M_bucket;
-      size_t _M_bucket_count;
+      size_t _M_bucket = 0;
+      size_t _M_bucket_count = 0;
 
     public:
       size_t
@@ -1194,7 +1194,7 @@ namespace __detail
       using __hash_obj_storage = _Hash_obj_storage<_Hash>;
       using __node_iter_base = _Node_iterator_base<_Value, false>;
 
-      _Local_iterator_base() : _M_bucket_count(-1) { }
+      _Local_iterator_base() = default;
 
       _Local_iterator_base(const __hash_code_base& __base,
                           _Hash_node<_Value, false>* __p,
@@ -1242,8 +1242,8 @@ namespace __detail
          }
       }
 
-      size_t _M_bucket;
-      size_t _M_bucket_count;
+      size_t _M_bucket = 0;
+      size_t _M_bucket_count = -1;
 
       void
       _M_init(const _Hash& __h)

Reply via email to