public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-10310] libstdc++: Use std::addressof in ranges::uninitialized_xxx [PR101571] Date: Fri, 26 Nov 2021 16:35:11 +0000 (GMT) [thread overview] Message-ID: <20211126163511.821AE3857C74@sourceware.org> (raw) https://gcc.gnu.org/g:0d480b8403f2541402adeed82deb7eb028330b87 commit r10-10310-g0d480b8403f2541402adeed82deb7eb028330b87 Author: Jonathan Wakely <jwakely@redhat.com> 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 <jwakely@redhat.com> 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<typename U> void operator,(const U&) const = delete; + + void operator&() const = delete; #else private: template<typename U> void operator,(const U&) const; + + void operator&() const; #endif }; @@ -275,10 +279,14 @@ namespace __gnu_test #if __cplusplus >= 201103L template<typename U> void operator,(const U&) const = delete; + + void operator&() const = delete; #else private: template<typename U> void operator,(const U&) const; + + void operator&() const; #endif };
reply other threads:[~2021-11-26 16:35 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211126163511.821AE3857C74@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).