From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1720) id 6941A385DC2B; Sat, 17 Feb 2024 14:12:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6941A385DC2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708179168; bh=xicS+bBN8ADPgAvBDSO+cb0OZe9UYTEOPSTD6juRHXc=; h=From:To:Subject:Date:From; b=iqmVoz7UUfSEMNbxt4rkt0MPtKuNYllw8KRWzMdA4/LYC0zD2MGpe9UQjI05/kj5J eaplGTSAmw8IghwIIoiejfH2qRt/83M19nQ3kr3QQ/yaImtWBxD9NKEdcmqI0e63nX A0S4KVB433lhw/jvBh+5EA5INPOYwpehXdLLYGGQ= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Francois Dumont To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-9046] libstdc++: [_GLIBCXX_DEBUG] Fix std::__niter_base behavior X-Act-Checkin: gcc X-Git-Author: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Git-Refname: refs/heads/master X-Git-Oldrev: 76aac40f5ecbc9cfb3b8734d181599e1b5a24bdf X-Git-Newrev: 9739d7ebf05aefcdd85477900528d8bee69df215 Message-Id: <20240217141248.6941A385DC2B@sourceware.org> Date: Sat, 17 Feb 2024 14:12:48 +0000 (GMT) List-Id: https://gcc.gnu.org/g:9739d7ebf05aefcdd85477900528d8bee69df215 commit r14-9046-g9739d7ebf05aefcdd85477900528d8bee69df215 Author: François Dumont Date: Wed Feb 14 06:59:12 2024 +0100 libstdc++: [_GLIBCXX_DEBUG] Fix std::__niter_base behavior std::__niter_base is used in _GLIBCXX_DEBUG mode to remove _Safe_iterator<> wrapper on random access iterators. But doing so it should also preserve original behavior to remove __normal_iterator wrapper. libstdc++-v3/ChangeLog: * include/bits/stl_algobase.h (std::__niter_base): Redefine the overload definitions for __gnu_debug::_Safe_iterator. * include/debug/safe_iterator.tcc (std::__niter_base): Adapt declarations. Diff: --- libstdc++-v3/include/bits/stl_algobase.h | 16 +++++++++++++++- libstdc++-v3/include/debug/safe_iterator.tcc | 18 +++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index e7207f672665..0f73da131729 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -317,12 +317,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_NOEXCEPT_IF(std::is_nothrow_copy_constructible<_Iterator>::value) { return __it; } +#if __cplusplus < 201103L template - _GLIBCXX20_CONSTEXPR _Ite __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, std::random_access_iterator_tag>&); + template + _Ite + __niter_base(const ::__gnu_debug::_Safe_iterator< + ::__gnu_cxx::__normal_iterator<_Ite, _Cont>, _Seq, + std::random_access_iterator_tag>&); +#else + template + _GLIBCXX20_CONSTEXPR + decltype(std::__niter_base(std::declval<_Ite>())) + __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, + std::random_access_iterator_tag>&) + noexcept(std::is_nothrow_copy_constructible<_Ite>::value); +#endif + // Reverse the __niter_base transformation to get a // __normal_iterator back again (this assumes that __normal_iterator // is only used to wrap random access iterators, like pointers). diff --git a/libstdc++-v3/include/debug/safe_iterator.tcc b/libstdc++-v3/include/debug/safe_iterator.tcc index 6eb70cbda049..a8b24233e854 100644 --- a/libstdc++-v3/include/debug/safe_iterator.tcc +++ b/libstdc++-v3/include/debug/safe_iterator.tcc @@ -235,13 +235,29 @@ namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION +#if __cplusplus < 201103L template - _GLIBCXX20_CONSTEXPR _Ite __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, std::random_access_iterator_tag>& __it) { return __it.base(); } + template + _Ite + __niter_base(const ::__gnu_debug::_Safe_iterator< + ::__gnu_cxx::__normal_iterator<_Ite, _Cont>, _DbgSeq, + std::random_access_iterator_tag>& __it) + { return __it.base().base(); } +#else + template + _GLIBCXX20_CONSTEXPR + decltype(std::__niter_base(std::declval<_Ite>())) + __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq, + std::random_access_iterator_tag>& __it) + noexcept(std::is_nothrow_copy_constructible<_Ite>::value) + { return std::__niter_base(__it.base()); } +#endif + template _GLIBCXX20_CONSTEXPR