2015-06-17 Jonathan Wakely <jwakely@redhat.com>
+ * include/bits/forward_list.h (forward_list::_M_get_Node_allocator):
+ Remove unnecessary uses of operator& and static_cast.
+ * include/bits/forward_list.tcc
+ (forward_list::operator=(const forward_list&)): Use __addressof
+ instead of operator&.
+ (forward_list::remove(const _Tp&), forward_list::remove(_Pred)):
+ Remove invalid static_casts.
+ * include/debug/forward_list: Use __addressof instead of operator&.
+ * testsuite/23_containers/forward_list/modifiers/addressof.cc: New.
+
* include/ext/alloc_traits.h (__alloc_traits::_S_nothrow_swap()): Use
__is_nothrow_swappable.
forward_list<_Tp, _Alloc>::
operator=(const forward_list& __list)
{
- if (&__list != this)
+ if (std::__addressof(__list) != this)
{
if (_Node_alloc_traits::_S_propagate_on_copy_assign())
{
forward_list<_Tp, _Alloc>::
remove(const _Tp& __val)
{
- _Node* __curr = static_cast<_Node*>(&this->_M_impl._M_head);
- _Node* __extra = 0;
+ _Node_base* __curr = &this->_M_impl._M_head;
+ _Node_base* __extra = nullptr;
while (_Node* __tmp = static_cast<_Node*>(__curr->_M_next))
{
else
__extra = __curr;
}
- __curr = static_cast<_Node*>(__curr->_M_next);
+ __curr = __curr->_M_next;
}
if (__extra)
forward_list<_Tp, _Alloc>::
remove_if(_Pred __pred)
{
- _Node* __curr = static_cast<_Node*>(&this->_M_impl._M_head);
+ _Node_base* __curr = &this->_M_impl._M_head;
while (_Node* __tmp = static_cast<_Node*>(__curr->_M_next))
{
if (__pred(*__tmp->_M_valptr()))
this->_M_erase_after(__curr);
else
- __curr = static_cast<_Node*>(__curr->_M_next);
+ __curr = __curr->_M_next;
}
}
__bbegin_its = __victim_base;
}
else
- __victim_base->_M_sequence = &__lhs;
+ __victim_base->_M_sequence = std::__addressof(__lhs);
}
if (__bbegin_its)
splice_after(const_iterator __pos, forward_list&& __list)
{
__glibcxx_check_insert_after(__pos);
- _GLIBCXX_DEBUG_VERIFY(&__list != this,
+ _GLIBCXX_DEBUG_VERIFY(std::__addressof(__list) != this,
_M_message(__gnu_debug::__msg_self_splice)
._M_sequence(*this, "this"));
_GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(),
_GLIBCXX_DEBUG_VERIFY(__i._M_before_dereferenceable(),
_M_message(__gnu_debug::__msg_splice_bad)
._M_iterator(__i, "__i"));
- _GLIBCXX_DEBUG_VERIFY(__i._M_attached_to(&__list),
+ _GLIBCXX_DEBUG_VERIFY(__i._M_attached_to(std::__addressof(__list)),
_M_message(__gnu_debug::__msg_splice_other)
._M_iterator(__i, "__i")
._M_sequence(__list, "__list"));
splice_after(const_iterator __pos, forward_list&& __list,
const_iterator __before, const_iterator __last)
{
+ auto __listptr = std::__addressof(__list);
__glibcxx_check_insert_after(__pos);
__glibcxx_check_valid_range(__before, __last);
- _GLIBCXX_DEBUG_VERIFY(__before._M_attached_to(&__list),
+ _GLIBCXX_DEBUG_VERIFY(__before._M_attached_to(__listptr),
_M_message(__gnu_debug::__msg_splice_other)
._M_sequence(__list, "list")
._M_iterator(__before, "before"));
._M_sequence(__list, "list")
._M_iterator(__before, "before")
._M_iterator(__last, "last"));
- _GLIBCXX_DEBUG_VERIFY(&__list != this || __tmp != __pos.base(),
+ _GLIBCXX_DEBUG_VERIFY(__listptr != this || __tmp != __pos.base(),
_M_message(__gnu_debug::__msg_splice_overlap)
._M_iterator(__tmp, "position")
._M_iterator(__before, "before")
void
merge(forward_list&& __list)
{
- if (this != &__list)
+ if (this != std::__addressof(__list))
{
__glibcxx_check_sorted(_Base::begin(), _Base::end());
__glibcxx_check_sorted(__list._M_base().begin(),
void
merge(forward_list&& __list, _Comp __comp)
{
- if (this != &__list)
+ if (this != std::__addressof(__list))
{
__glibcxx_check_sorted_pred(_Base::begin(), _Base::end(), __comp);
__glibcxx_check_sorted_pred(__list._M_base().begin(),
--- /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 <forward_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::forward_list<N::X>;