I'd like to commit this code cleanup. It is not fixing anything except perhaps for some code analysis tools reporting minor issues.

Despite being trivial and limited to _GLIBCCX_DEBUG I'd like to have some feedback at least on the ChangeLog, to make sure I've used the right C++ words.

    libstdc++: [_GLIBCXX_DEBUG] _Safe_iterator_base/_Safe_sequence_base code cleanup

    Use inlined initialization for both _Safe_iterator_base and
    _Safe_sequence_base and so default their default constructor.

    Have _Safe_sequence_base copy constructor always defined, using same
    implementation as the default constructor.

    Use value-initialization syntax when setting pointers to nullptr before C++11
    instead of using 0.

    libstdc++-v3/ChangeLog:

            * include/debug/safe_base.h
            [__cplusplus >= 201103L]
            (_Safe_iterator_base::_M_sequence): Add inline initialization.
            (_Safe_iterator_base::_M_version): Likewise.
            (_Safe_iterator_base::_M_prior): Likewise.
            (_Safe_iterator_base::_M_next): Likewise.
            [__cplusplus < 201103L](_Safe_iterator_base()): Value initialize members.             [__cplusplus >= 201103L](_Safe_iterator_base()): Default implementation.             (_Safe_iterator_base(const _Safe_sequence_base*, bool)): Value initialize members.             (_Safe_iterator_base(const _Safe_iterator_base&, bool)): Likewise.
            [__cplusplus >= 201103L]
            (_Safe_sequence_base::_M_iterators): Add inline initialization.
            (_Safe_sequence_base::_M_const_iterators): Likewise.
            (_Safe_sequence_base::_M_version): Likewise.
            [__cplusplus < 201103L](_Safe_sequence_base()): Value initialize members.             [__cplusplus >= 201103L](_Safe_sequence_base()): Default implementation.             [__cplusplus < 201103L](_Safe_sequence_base(const _Safe_sequence_base&)): New.

Tested under Linux x86_64 C++98 and C++20 _GLIBCXX_DEBUG mode.

Ok to commit ?

François

diff --git a/libstdc++-v3/include/debug/safe_base.h 
b/libstdc++-v3/include/debug/safe_base.h
index 6ea499ef239..d188fd6e968 100644
--- a/libstdc++-v3/include/debug/safe_base.h
+++ b/libstdc++-v3/include/debug/safe_base.h
@@ -56,7 +56,12 @@ namespace __gnu_debug
      *  a singular iterator. Stored as pointer-to-const because sequence
      *  could be declared as const.
      */
-    const _Safe_sequence_base* _M_sequence;
+    const _Safe_sequence_base*
+#if __cplusplus < 201103L
+                               _M_sequence;
+#else
+                               _M_sequence = nullptr;
+#endif
 
     /** The version number of this iterator. The sentinel value 0 is
      *  used to indicate an invalidated iterator (i.e., one that is
@@ -65,22 +70,41 @@ namespace __gnu_debug
      *  referenced by _M_sequence for the iterator to be
      *  non-singular.
      */
-    unsigned int               _M_version;
+    unsigned int
+#if __cplusplus < 201103L
+                               _M_version;
+#else
+                               _M_version = 0;
+#endif
 
     /** Pointer to the previous iterator in the sequence's list of
        iterators. Only valid when _M_sequence != NULL. */
-    _Safe_iterator_base*       _M_prior;
+    _Safe_iterator_base*
+#if __cplusplus < 201103L
+                               _M_prior;
+#else
+                               _M_prior = nullptr;
+#endif
 
     /** Pointer to the next iterator in the sequence's list of
        iterators. Only valid when _M_sequence != NULL. */
-    _Safe_iterator_base*       _M_next;
+    _Safe_iterator_base*
+#if __cplusplus < 201103L
+                               _M_next;
+#else
+                               _M_next = nullptr;
+#endif
 
   protected:
     /** Initializes the iterator and makes it singular. */
     _GLIBCXX20_CONSTEXPR
     _Safe_iterator_base()
-    : _M_sequence(0), _M_version(0), _M_prior(0), _M_next(0)
+#if __cplusplus < 201103L
+    : _M_sequence(), _M_version(), _M_prior(), _M_next()
     { }
+#else
+    = default;
+#endif
 
     /** Initialize the iterator to reference the sequence pointed to
      *  by @p __seq. @p __constant is true when we are initializing a
@@ -91,7 +115,7 @@ namespace __gnu_debug
      */
     _GLIBCXX20_CONSTEXPR
     _Safe_iterator_base(const _Safe_sequence_base* __seq, bool __constant)
-    : _M_sequence(0), _M_version(0), _M_prior(0), _M_next(0)
+    : _M_sequence(), _M_version(), _M_prior(), _M_next()
     {
       if (!std::__is_constant_evaluated())
        this->_M_attach(__seq, __constant);
@@ -102,7 +126,7 @@ namespace __gnu_debug
        iterator, and false if it is mutable. */
     _GLIBCXX20_CONSTEXPR
     _Safe_iterator_base(const _Safe_iterator_base& __x, bool __constant)
-    : _M_sequence(0), _M_version(0), _M_prior(0), _M_next(0)
+    : _M_sequence(), _M_version(), _M_prior(), _M_next()
     {
       if (!std::__is_constant_evaluated())
        this->_M_attach(__x._M_sequence, __constant);
@@ -221,22 +245,45 @@ namespace __gnu_debug
 
   public:
     /// The list of mutable iterators that reference this container
-    mutable _Safe_iterator_base* _M_iterators;
+    mutable _Safe_iterator_base*
+#if __cplusplus < 201103L
+                                       _M_iterators;
+#else
+                                       _M_iterators = nullptr;
+#endif
 
     /// The list of constant iterators that reference this container
-    mutable _Safe_iterator_base* _M_const_iterators;
+    mutable _Safe_iterator_base*
+#if __cplusplus < 201103L
+                                       _M_const_iterators;
+#else
+                                       _M_const_iterators = nullptr;
+#endif
 
     /// The container version number. This number may never be 0.
-    mutable unsigned int _M_version;
+    mutable unsigned int
+#if __cplusplus < 201103L
+                                       _M_version;
+#else
+                                       _M_version = 1;
+#endif
 
   protected:
     // Initialize with a version number of 1 and no iterators
     _GLIBCXX20_CONSTEXPR
-    _Safe_sequence_base() _GLIBCXX_NOEXCEPT
-    : _M_iterators(0), _M_const_iterators(0), _M_version(1)
+    _Safe_sequence_base()
+#if __cplusplus < 201103L
+    : _M_iterators(), _M_const_iterators(), _M_version(1)
     { }
+#else
+    = default;
+#endif
 
-#if __cplusplus >= 201103L
+#if __cplusplus < 201103L
+    _Safe_sequence_base(const _Safe_sequence_base&)
+    : _M_iterators(), _M_const_iterators(), _M_version(1)
+    { }
+#else
     _GLIBCXX20_CONSTEXPR
     _Safe_sequence_base(const _Safe_sequence_base&) noexcept
     : _Safe_sequence_base() { }

Reply via email to