]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Use std::addressof to avoid ADL for operator& [PR 60497]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 30 Apr 2021 13:45:42 +0000 (14:45 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 30 Apr 2021 13:57:40 +0000 (14:57 +0100)
This is another small step towards avoiding the problems described in PR
60497, by using std::addressof to avoid ADL, so that we don't require
all template arguments to be complete.

libstdc++-v3/ChangeLog:

PR libstdc++/60497
* include/bits/basic_ios.tcc (basic_ios::copyfmt): use
std::addressof.
* include/bits/basic_string.tcc (basic_string::swap)
(basic_string::assign): Likewise.
* include/bits/deque.tcc (deque::operator=(const deque&)):
Likewise.
* include/bits/stl_tree.h (_Rb_tree::operator=(const * _Rb_tree&)):
Likewise.
* include/bits/vector.tcc (vector::operator=(const vector&)):
Likewise.

libstdc++-v3/include/bits/basic_ios.tcc
libstdc++-v3/include/bits/basic_string.tcc
libstdc++-v3/include/bits/deque.tcc
libstdc++-v3/include/bits/stl_tree.h
libstdc++-v3/include/bits/vector.tcc

index f79aad97cf03884a8402c3bfd8bfd7d68ae4f25a..6285f734031c2cb5139cc2d81d996da46904efe9 100644 (file)
@@ -64,7 +64,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // 292. effects of a.copyfmt (a)
-      if (this != &__rhs)
+      if (this != std::__addressof(__rhs))
        {
          // Per 27.1.1, do not call imbue, yet must trash all caches
          // associated with imbue()
index 35b60865f5827a756c75887dec321728c9fab7a5..0c13e7447476cc341b69a367a357afa6f6700fc5 100644 (file)
@@ -58,7 +58,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     basic_string<_CharT, _Traits, _Alloc>::
     swap(basic_string& __s) _GLIBCXX_NOEXCEPT
     {
-      if (this == &__s)
+      if (this == std::__addressof(__s))
        return;
 
       _Alloc_traits::_S_on_swap(_M_get_allocator(), __s._M_get_allocator());
@@ -254,7 +254,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     basic_string<_CharT, _Traits, _Alloc>::
     _M_assign(const basic_string& __str)
     {
-      if (this != &__str)
+      if (this != std::__addressof(__str))
        {
          const size_type __rsize = __str.length();
          const size_type __capacity = capacity();
index db532e3c585bbee086a8eb9a23315d3c0db2304c..ab1f49813df55f28588e05a97569da56833eaf9a 100644 (file)
@@ -95,7 +95,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
     deque<_Tp, _Alloc>::
     operator=(const deque& __x)
     {
-      if (&__x != this)
+      if (std::__addressof(__x) != this)
        {
 #if __cplusplus >= 201103L
          if (_Alloc_traits::_S_propagate_on_copy_assign())
index 550195a2749d07b3cf04c3c409777f41967215c0..962991298104a141e66e4632bfa20d709685d10b 100644 (file)
@@ -1729,7 +1729,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
     operator=(const _Rb_tree& __x)
     {
-      if (this != &__x)
+      if (this != std::__addressof(__x))
        {
          // Note that _Key may be a constant type.
 #if __cplusplus >= 201103L
index 8a6a99fb5373eb82f8f1b3bc9832cda298def15d..caee5cbfc2f6ffbc6a0e8e904b256b2007a49120 100644 (file)
@@ -198,7 +198,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
     vector<_Tp, _Alloc>::
     operator=(const vector<_Tp, _Alloc>& __x)
     {
-      if (&__x != this)
+      if (std::__addressof(__x) != this)
        {
          _GLIBCXX_ASAN_ANNOTATE_REINIT;
 #if __cplusplus >= 201103L