libstdc++: Use std::addressof to avoid ADL for operator& [PR 60497]

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.
This commit is contained in:
Jonathan Wakely
2021-04-30 14:45:42 +01:00
parent aa475c4ac8
commit 47915ef847
5 changed files with 6 additions and 6 deletions

View 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()

View 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();

View 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())

View 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

View 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