Indeed, here is the one committed.
On 7/14/26 22:42, Jonathan Wakely wrote:
Looks like you've attached a different patch
On Tue, 14 Jul 2026, 20:24 François Dumont, <[email protected]> wrote:
libstdc++: [_GLIBCXX_DEBUG] Make constant evaluation compatible
Cleanup _Safe_iterator and _Safe_local_iterator implementations.
Use base constructor for the special _Unchecked constructor.
Remove intermediate typedefs, use directly the template parameter
type
and the base class.
libstdc++-v3/ChangeLog:
* include/debug/safe_iterator.h
(_Safe_iterator::_Iter_base, _Safe_iterator::_Safe_base):
Remove.
(_Safe_iterator(const _Safe_iterator&, _Unchecked)):
Delegate
to correct base classes
constructors.
* include/debug/safe_local_iterator.h
(_Safe_local_iterator::_Iter_base,
_Safe_local_iterator::_Safe_base): Remove.
(_Safe_local_iterator(const _Safe_local_iterator&,
_Unchecked)): Delegate to the correct
base classes constructors.
Tested under Linux x86_64 _GLIBCXX_DEBUG mode.
François
diff --git a/libstdc++-v3/include/debug/safe_iterator.h
b/libstdc++-v3/include/debug/safe_iterator.h
index 77e45ae073e..ceda5575a52 100644
--- a/libstdc++-v3/include/debug/safe_iterator.h
+++ b/libstdc++-v3/include/debug/safe_iterator.h
@@ -131,9 +131,6 @@ namespace __gnu_debug
: private _Iterator,
public _Safe_iterator_base
{
- typedef _Iterator _Iter_base;
- typedef _Safe_iterator_base _Safe_base;
-
typedef std::iterator_traits<_Iterator> _Traits;
protected:
@@ -149,11 +146,8 @@ namespace __gnu_debug
_GLIBCXX20_CONSTEXPR
_Safe_iterator(const _Safe_iterator& __x, _Unchecked) _GLIBCXX_NOEXCEPT
- : _Iter_base(__x.base()), _Safe_base()
- {
- if (!std::__is_constant_evaluated())
- _M_attach(__x._M_sequence);
- }
+ : _Iterator(__x), _Safe_iterator_base(__x, _S_constant())
+ { }
public:
typedef _Iterator iterator_type;
@@ -169,7 +163,7 @@ namespace __gnu_debug
/// @post the iterator is singular and unattached
_GLIBCXX20_CONSTEXPR
- _Safe_iterator() _GLIBCXX_NOEXCEPT : _Iter_base() { }
+ _Safe_iterator() _GLIBCXX_NOEXCEPT : _Iterator() { }
/**
* @brief Safe iterator construction from an unsafe iterator and
@@ -181,7 +175,7 @@ namespace __gnu_debug
_GLIBCXX20_CONSTEXPR
_Safe_iterator(_Iterator __i, const _Safe_sequence_base* __seq)
_GLIBCXX_NOEXCEPT
- : _Iter_base(__i), _Safe_base(__seq, _S_constant())
+ : _Iterator(__i), _Safe_iterator_base(__seq, _S_constant())
{ }
/**
@@ -189,7 +183,7 @@ namespace __gnu_debug
*/
_GLIBCXX20_CONSTEXPR
_Safe_iterator(const _Safe_iterator& __x) _GLIBCXX_NOEXCEPT
- : _Iter_base(__x.base()), _Safe_base()
+ : _Iterator(__x), _Safe_iterator_base()
{
if (std::__is_constant_evaluated())
return;
@@ -211,7 +205,7 @@ namespace __gnu_debug
*/
_GLIBCXX20_CONSTEXPR
_Safe_iterator(_Safe_iterator&& __x) noexcept
- : _Iter_base()
+ : _Iterator()
{
if (std::__is_constant_evaluated())
{
@@ -243,7 +237,7 @@ namespace __gnu_debug
std::__are_same<_MutableIterator, _OtherIterator>::__value,
_Category>::__type>& __x)
_GLIBCXX_NOEXCEPT
- : _Iter_base(__x.base())
+ : _Iterator(__x.base())
{
if (std::__is_constant_evaluated())
return;
@@ -446,12 +440,12 @@ namespace __gnu_debug
/** Attach iterator to the given sequence. */
void
_M_attach(const _Safe_sequence_base* __seq)
- { _Safe_base::_M_attach(__seq, _S_constant()); }
+ { _Safe_iterator_base::_M_attach(__seq, _S_constant()); }
/** Likewise, but not thread-safe. */
void
_M_attach_single(const _Safe_sequence_base* __seq)
- { _Safe_base::_M_attach_single(__seq, _S_constant()); }
+ { _Safe_iterator_base::_M_attach_single(__seq, _S_constant()); }
/// Is the iterator dereferenceable?
bool
@@ -478,7 +472,7 @@ namespace __gnu_debug
/// Is the iterator value-initialized?
bool
_M_value_initialized() const
- { return _M_version == 0 && base() == _Iter_base(); }
+ { return _M_version == 0 && base() == _Iterator(); }
// Can we advance the iterator @p __n steps (@p __n may be negative)
bool
diff --git a/libstdc++-v3/include/debug/safe_local_iterator.h
b/libstdc++-v3/include/debug/safe_local_iterator.h
index d37168a040b..18b7b0b6191 100644
--- a/libstdc++-v3/include/debug/safe_local_iterator.h
+++ b/libstdc++-v3/include/debug/safe_local_iterator.h
@@ -65,9 +65,6 @@ namespace __gnu_debug
: private _Iterator
, public _Safe_local_iterator_base
{
- typedef _Iterator _Iter_base;
- typedef _Safe_local_iterator_base _Safe_base;
-
typedef typename _UContainer::size_type size_type;
typedef std::iterator_traits<_Iterator> _Traits;
@@ -85,10 +82,9 @@ namespace __gnu_debug
struct _Unchecked { };
- _Safe_local_iterator(const _Safe_local_iterator& __x,
- _Unchecked) noexcept
- : _Iter_base(__x.base())
- { _M_attach(__x._M_safe_container()); }
+ _Safe_local_iterator(const _Safe_local_iterator& __x, _Unchecked)
noexcept
+ : _Iterator(__x), _Safe_local_iterator_base(__x, _S_constant())
+ { }
public:
typedef _Iterator iterator_type;
@@ -99,7 +95,7 @@ namespace __gnu_debug
typedef typename _Traits::pointer pointer;
/// @post the iterator is singular and unattached
- _Safe_local_iterator() noexcept : _Iter_base() { }
+ _Safe_local_iterator() noexcept : _Iterator() { }
/**
* @brief Safe iterator construction from an unsafe iterator and
@@ -110,14 +106,14 @@ namespace __gnu_debug
*/
_Safe_local_iterator(_Iterator __i,
const _Safe_unordered_container_base* __cont)
- : _Iter_base(__i), _Safe_base(__cont, _S_constant())
+ : _Iterator(__i), _Safe_local_iterator_base(__cont, _S_constant())
{ }
/**
* @brief Copy construction.
*/
_Safe_local_iterator(const _Safe_local_iterator& __x) noexcept
- : _Iter_base(__x.base())
+ : _Iterator(__x)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 408. Is vector<reverse_iterator<char*> > forbidden?
@@ -134,7 +130,7 @@ namespace __gnu_debug
* @post __x is singular and unattached
*/
_Safe_local_iterator(_Safe_local_iterator&& __x) noexcept
- : _Iter_base()
+ : _Iterator()
{
_GLIBCXX_DEBUG_VERIFY(!__x._M_singular()
|| __x._M_value_initialized(),
@@ -157,7 +153,7 @@ namespace __gnu_debug
typename __gnu_cxx::__enable_if<_IsConstant::__value &&
std::__are_same<_MutableIterator, _OtherIterator>::__value,
_UContainer>::__type>& __x) noexcept
- : _Iter_base(__x.base())
+ : _Iterator(__x.base())
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 408. Is vector<reverse_iterator<char*> > forbidden?
@@ -321,12 +317,12 @@ namespace __gnu_debug
/** Attach iterator to the given unordered container. */
void
_M_attach(const _Safe_unordered_container_base* __cont)
- { _Safe_base::_M_attach(__cont, _S_constant()); }
+ { _Safe_local_iterator_base::_M_attach(__cont, _S_constant()); }
/** Likewise, but not thread-safe. */
void
_M_attach_single(const _Safe_unordered_container_base* __cont)
- { _Safe_base::_M_attach_single(__cont, _S_constant()); }
+ { _Safe_local_iterator_base::_M_attach_single(__cont, _S_constant()); }
/// Is the iterator dereferenceable?
bool
@@ -341,7 +337,7 @@ namespace __gnu_debug
/// Is the iterator value-initialized?
bool
_M_value_initialized() const
- { return _M_version == 0 && base() == _Iter_base{}; }
+ { return _M_version == 0 && base() == _Iterator{}; }
// Is the iterator range [*this, __rhs) valid?
bool