From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 821AE3857C74; Fri, 26 Nov 2021 16:35:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 821AE3857C74 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-10310] libstdc++: Use std::addressof in ranges::uninitialized_xxx [PR101571] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 30033d9bb9d5e5303fadf448999f4f27e2693ed6 X-Git-Newrev: 0d480b8403f2541402adeed82deb7eb028330b87 Message-Id: <20211126163511.821AE3857C74@sourceware.org> Date: Fri, 26 Nov 2021 16:35:11 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Nov 2021 16:35:11 -0000 https://gcc.gnu.org/g:0d480b8403f2541402adeed82deb7eb028330b87 commit r10-10310-g0d480b8403f2541402adeed82deb7eb028330b87 Author: Jonathan Wakely Date: Thu Jul 22 14:37:24 2021 +0100 libstdc++: Use std::addressof in ranges::uninitialized_xxx [PR101571] Make the ranges::uninitialized_xxx algorithms use std::addressof to protect against iterator types that overload operator&. Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: PR libstdc++/101571 * include/bits/ranges_uninitialized.h (_DestroyGuard): Change constructor parameter to reference and use addressof. * testsuite/util/testsuite_iterators.h: Define deleted operator& overloads for test iterators. (cherry picked from commit aca7a0253d6e3116f846ad530b19d89644a64267) Diff: --- libstdc++-v3/include/bits/ranges_uninitialized.h | 26 +++++++++++------------ libstdc++-v3/testsuite/util/testsuite_iterators.h | 8 +++++++ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/libstdc++-v3/include/bits/ranges_uninitialized.h b/libstdc++-v3/include/bits/ranges_uninitialized.h index 25e664de753..434df6da2b7 100644 --- a/libstdc++-v3/include/bits/ranges_uninitialized.h +++ b/libstdc++-v3/include/bits/ranges_uninitialized.h @@ -106,8 +106,8 @@ namespace ranges public: explicit - _DestroyGuard(const _Iter* __iter) - : _M_first(*__iter), _M_cur(__iter) + _DestroyGuard(const _Iter& __iter) + : _M_first(__iter), _M_cur(std::__addressof(__iter)) { } void @@ -127,7 +127,7 @@ namespace ranges struct _DestroyGuard<_Iter> { explicit - _DestroyGuard(const _Iter*) + _DestroyGuard(const _Iter&) { } void @@ -149,7 +149,7 @@ namespace ranges return ranges::next(__first, __last); else { - auto __guard = __detail::_DestroyGuard(&__first); + auto __guard = __detail::_DestroyGuard(__first); for (; __first != __last; ++__first) ::new (__detail::__voidify(*__first)) _ValueType; __guard.release(); @@ -181,7 +181,7 @@ namespace ranges return ranges::next(__first, __n); else { - auto __guard = __detail::_DestroyGuard(&__first); + auto __guard = __detail::_DestroyGuard(__first); for (; __n > 0; ++__first, (void) --__n) ::new (__detail::__voidify(*__first)) _ValueType; __guard.release(); @@ -207,7 +207,7 @@ namespace ranges return ranges::fill(__first, __last, _ValueType()); else { - auto __guard = __detail::_DestroyGuard(&__first); + auto __guard = __detail::_DestroyGuard(__first); for (; __first != __last; ++__first) ::new (__detail::__voidify(*__first)) _ValueType(); __guard.release(); @@ -240,7 +240,7 @@ namespace ranges return ranges::fill_n(__first, __n, _ValueType()); else { - auto __guard = __detail::_DestroyGuard(&__first); + auto __guard = __detail::_DestroyGuard(__first); for (; __n > 0; ++__first, (void) --__n) ::new (__detail::__voidify(*__first)) _ValueType(); __guard.release(); @@ -279,7 +279,7 @@ namespace ranges } else { - auto __guard = __detail::_DestroyGuard(&__ofirst); + auto __guard = __detail::_DestroyGuard(__ofirst); for (; __ifirst != __ilast && __ofirst != __olast; ++__ofirst, (void)++__ifirst) ::new (__detail::__voidify(*__ofirst)) _OutType(*__ifirst); @@ -326,7 +326,7 @@ namespace ranges } else { - auto __guard = __detail::_DestroyGuard(&__ofirst); + auto __guard = __detail::_DestroyGuard(__ofirst); for (; __n > 0 && __ofirst != __olast; ++__ofirst, (void)++__ifirst, (void)--__n) ::new (__detail::__voidify(*__ofirst)) _OutType(*__ifirst); @@ -368,7 +368,7 @@ namespace ranges } else { - auto __guard = __detail::_DestroyGuard(&__ofirst); + auto __guard = __detail::_DestroyGuard(__ofirst); for (; __ifirst != __ilast && __ofirst != __olast; ++__ofirst, (void)++__ifirst) ::new (__detail::__voidify(*__ofirst)) @@ -419,7 +419,7 @@ namespace ranges } else { - auto __guard = __detail::_DestroyGuard(&__ofirst); + auto __guard = __detail::_DestroyGuard(__ofirst); for (; __n > 0 && __ofirst != __olast; ++__ofirst, (void)++__ifirst, (void)--__n) ::new (__detail::__voidify(*__ofirst)) @@ -446,7 +446,7 @@ namespace ranges return ranges::fill(__first, __last, __x); else { - auto __guard = __detail::_DestroyGuard(&__first); + auto __guard = __detail::_DestroyGuard(__first); for (; __first != __last; ++__first) ::new (__detail::__voidify(*__first)) _ValueType(__x); __guard.release(); @@ -479,7 +479,7 @@ namespace ranges return ranges::fill_n(__first, __n, __x); else { - auto __guard = __detail::_DestroyGuard(&__first); + auto __guard = __detail::_DestroyGuard(__first); for (; __n > 0; ++__first, (void)--__n) ::new (__detail::__voidify(*__first)) _ValueType(__x); __guard.release(); diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h index 8c4b8b7c6cc..241b8a9ec2c 100644 --- a/libstdc++-v3/testsuite/util/testsuite_iterators.h +++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h @@ -175,10 +175,14 @@ namespace __gnu_test #if __cplusplus >= 201103L template void operator,(const U&) const = delete; + + void operator&() const = delete; #else private: template void operator,(const U&) const; + + void operator&() const; #endif }; @@ -275,10 +279,14 @@ namespace __gnu_test #if __cplusplus >= 201103L template void operator,(const U&) const = delete; + + void operator&() const = delete; #else private: template void operator,(const U&) const; + + void operator&() const; #endif };