2015-06-16 Jonathan Wakely <jwakely@redhat.com>
+ * include/bits/list.tcc (list::operator=(const list&), list::merge):
+ Use __addressof instead of operator&.
+ (list::sort): Use array-to-pointer decay instead of operator&.
+ * include/bits/stl_list.h (list::splice): Use __addressof instead of
+ operator&.
+ * include/debug/formatter.h (_Error_formatter::_Parameter::_Parameter):
+ Likewise.
+ * include/debug/functions.h (__check_singular): Likewise.
+ * include/debug/list (list::splice, list::merge): Likewise.
+ * testsuite/23_containers/list/modifiers/addressof.cc: New.
+
PR libstdc++/65393
* src/c++11/thread.cc (thread::_M_make_thread): Replace shared_ptr
copies with moves.
list<_Tp, _Alloc>::
operator=(const list& __x)
{
- if (this != &__x)
+ if (this != std::__addressof(__x))
{
iterator __first1 = begin();
iterator __last1 = end();
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 300. list::merge() specification incomplete
- if (this != &__x)
+ if (this != std::__addressof(__x))
{
_M_check_equal_allocators(__x);
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 300. list::merge() specification incomplete
- if (this != &__x)
+ if (this != std::__addressof(__x))
{
_M_check_equal_allocators(__x);
{
list __carry;
list __tmp[64];
- list * __fill = &__tmp[0];
+ list * __fill = __tmp;
list * __counter;
do
{
__carry.splice(__carry.begin(), *this, begin());
- for(__counter = &__tmp[0];
+ for(__counter = __tmp;
__counter != __fill && !__counter->empty();
++__counter)
{
}
while ( !empty() );
- for (__counter = &__tmp[1]; __counter != __fill; ++__counter)
+ for (__counter = __tmp + 1; __counter != __fill; ++__counter)
__counter->merge(*(__counter - 1));
swap( *(__fill - 1) );
}
{
list __carry;
list __tmp[64];
- list * __fill = &__tmp[0];
+ list * __fill = __tmp;
list * __counter;
do
{
__carry.splice(__carry.begin(), *this, begin());
- for(__counter = &__tmp[0];
+ for(__counter = __tmp;
__counter != __fill && !__counter->empty();
++__counter)
{
}
while ( !empty() );
- for (__counter = &__tmp[1]; __counter != __fill; ++__counter)
+ for (__counter = __tmp + 1; __counter != __fill; ++__counter)
__counter->merge(*(__counter - 1), __comp);
swap(*(__fill - 1));
}
if (__position == __i || __position == __j)
return;
- if (this != &__x)
+ if (this != std::__addressof(__x))
_M_check_equal_allocators(__x);
this->_M_transfer(__position._M_const_cast(),
{
if (__first != __last)
{
- if (this != &__x)
+ if (this != std::__addressof(__x))
_M_check_equal_allocators(__x);
size_t __n = this->_M_distance(__first._M_node, __last._M_node);
: _M_kind(__iterator), _M_variant()
{
_M_variant._M_iterator._M_name = __name;
- _M_variant._M_iterator._M_address = &__it;
+ _M_variant._M_iterator._M_address = std::__addressof(__it);
_M_variant._M_iterator._M_type = _GLIBCXX_TYPEID(__it);
_M_variant._M_iterator._M_constness =
std::__are_same<_Safe_iterator<_Iterator, _Sequence>,
: _M_kind(__iterator), _M_variant()
{
_M_variant._M_iterator._M_name = __name;
- _M_variant._M_iterator._M_address = &__it;
+ _M_variant._M_iterator._M_address = std::__addressof(__it);
_M_variant._M_iterator._M_type = _GLIBCXX_TYPEID(__it);
_M_variant._M_iterator._M_constness =
std::__are_same<_Safe_local_iterator<_Iterator, _Sequence>,
: _M_kind(__iterator), _M_variant()
{
_M_variant._M_iterator._M_name = __name;
- _M_variant._M_iterator._M_address = &__it;
+ _M_variant._M_iterator._M_address = std::__addressof(__it);
_M_variant._M_iterator._M_type = _GLIBCXX_TYPEID(__it);
_M_variant._M_iterator._M_constness = __const_iterator;
_M_variant._M_iterator._M_state = __it ? __unknown_state : __singular;
: _M_kind(__iterator), _M_variant()
{
_M_variant._M_iterator._M_name = __name;
- _M_variant._M_iterator._M_address = &__it;
+ _M_variant._M_iterator._M_address = std::__addressof(__it);
_M_variant._M_iterator._M_type = _GLIBCXX_TYPEID(__it);
_M_variant._M_iterator._M_constness = __mutable_iterator;
_M_variant._M_iterator._M_state = __it ? __unknown_state : __singular;
: _M_kind(__iterator), _M_variant()
{
_M_variant._M_iterator._M_name = __name;
- _M_variant._M_iterator._M_address = &__it;
+ _M_variant._M_iterator._M_address = std::__addressof(__it);
_M_variant._M_iterator._M_type = _GLIBCXX_TYPEID(__it);
_M_variant._M_iterator._M_constness = __unknown_constness;
_M_variant._M_iterator._M_state =
{
_M_variant._M_sequence._M_name = __name;
_M_variant._M_sequence._M_address =
- static_cast<const _Sequence*>(&__seq);
+ static_cast<const _Sequence*>(std::__addressof(__seq));
_M_variant._M_sequence._M_type = _GLIBCXX_TYPEID(_Sequence);
}
: _M_kind(__sequence), _M_variant()
{
_M_variant._M_sequence._M_name = __name;
- _M_variant._M_sequence._M_address = &__seq;
+ _M_variant._M_sequence._M_address = std::__addressof(__seq);
_M_variant._M_sequence._M_type = _GLIBCXX_TYPEID(_Sequence);
}
template<typename _Iterator>
inline bool
__check_singular(const _Iterator& __x)
- { return __check_singular_aux(&__x); }
+ { return __check_singular_aux(std::__addressof(__x)); }
/** Non-NULL pointers are nonsingular. */
template<typename _Tp>
splice(iterator __position, list& __x)
#endif
{
- _GLIBCXX_DEBUG_VERIFY(&__x != this,
+ _GLIBCXX_DEBUG_VERIFY(std::__addressof(__x) != this,
_M_message(__gnu_debug::__msg_self_splice)
._M_sequence(*this, "this"));
this->_M_transfer_from_if(__x, _Not_equal(__x._M_base().end()));
_GLIBCXX_DEBUG_VERIFY(__i._M_dereferenceable(),
_M_message(__gnu_debug::__msg_splice_bad)
._M_iterator(__i, "__i"));
- _GLIBCXX_DEBUG_VERIFY(__i._M_attached_to(&__x),
+ _GLIBCXX_DEBUG_VERIFY(__i._M_attached_to(std::__addressof(__x)),
_M_message(__gnu_debug::__msg_splice_other)
._M_iterator(__i, "__i")._M_sequence(__x, "__x"));
{
__glibcxx_check_insert(__position);
__glibcxx_check_valid_range(__first, __last);
- _GLIBCXX_DEBUG_VERIFY(__first._M_attached_to(&__x),
+ _GLIBCXX_DEBUG_VERIFY(__first._M_attached_to(std::__addressof(__x)),
_M_message(__gnu_debug::__msg_splice_other)
._M_sequence(__x, "x")
._M_iterator(__first, "first"));
_M_message(__gnu_debug::__msg_valid_range)
._M_iterator(__first, "first")
._M_iterator(__last, "last"));
- _GLIBCXX_DEBUG_VERIFY(&__x != this || __tmp != __position.base(),
+ _GLIBCXX_DEBUG_VERIFY(std::__addressof(__x) != this
+ || __tmp != __position.base(),
_M_message(__gnu_debug::__msg_splice_overlap)
._M_iterator(__tmp, "position")
._M_iterator(__first, "first")
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 300. list::merge() specification incomplete
- if (this != &__x)
+ if (this != std::__addressof(__x))
{
__glibcxx_check_sorted(_Base::begin(), _Base::end());
__glibcxx_check_sorted(__x.begin().base(), __x.end().base());
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 300. list::merge() specification incomplete
- if (this != &__x)
+ if (this != std::__addressof(__x))
{
__glibcxx_check_sorted_pred(_Base::begin(), _Base::end(),
__comp);
--- /dev/null
+// Copyright (C) 2015 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+#include <list>
+
+namespace N
+{
+ // This operator& must not be found by ADL.
+ template<typename T> void operator&(const T&) { }
+ struct X { };
+ bool operator==(const X&, const X&);
+ bool operator<(const X&, const X&);
+}
+
+template class std::list<N::X>;