Commit 9f9eb84e by Jonathan Wakely Committed by Jonathan Wakely

libstdc++/70766 use std::addressof instead of operator&

	PR libstdc++/70766
	* include/bits/basic_ios.tcc (basic_ios::_M_cache_locale): Use
	__addressof.
	* include/bits/stream_iterator.h (istream_iterator, ostream_iterator):
	Likewise.
	* include/std/atomic (atomic<_Tp>): Likewise.
	* include/std/shared_mutex (shared_lock): Likewise.
	* testsuite/24_iterators/istream_iterator/70766.cc: New test.
	* testsuite/24_iterators/ostream_iterator/70766.cc : New test.
	* testsuite/29_atomics/atomic/60695.cc: Adjust dg-error line number.
	* testsuite/29_atomics/atomic/70766.cc: New test.
	* testsuite/30_threads/shared_lock/70766.cc: New test.

From-SVN: r235565
parent 272b2ce4
2016-04-28 Jonathan Wakely <jwakely@redhat.com> 2016-04-28 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/70766
* include/bits/basic_ios.tcc (basic_ios::_M_cache_locale): Use
__addressof.
* include/bits/stream_iterator.h (istream_iterator, ostream_iterator):
Likewise.
* include/std/atomic (atomic<_Tp>): Likewise.
* include/std/shared_mutex (shared_lock): Likewise.
* testsuite/24_iterators/istream_iterator/70766.cc: New test.
* testsuite/24_iterators/ostream_iterator/70766.cc : New test.
* testsuite/29_atomics/atomic/60695.cc: Adjust dg-error line number.
* testsuite/29_atomics/atomic/70766.cc: New test.
* testsuite/30_threads/shared_lock/70766.cc: New test.
* include/bits/hashtable_policy.h (__detail::_Insert_base, * include/bits/hashtable_policy.h (__detail::_Insert_base,
__detail::_Insert): Improve comments. __detail::_Insert): Improve comments.
......
...@@ -157,17 +157,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -157,17 +157,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
basic_ios<_CharT, _Traits>::_M_cache_locale(const locale& __loc) basic_ios<_CharT, _Traits>::_M_cache_locale(const locale& __loc)
{ {
if (__builtin_expect(has_facet<__ctype_type>(__loc), true)) if (__builtin_expect(has_facet<__ctype_type>(__loc), true))
_M_ctype = &use_facet<__ctype_type>(__loc); _M_ctype = std::__addressof(use_facet<__ctype_type>(__loc));
else else
_M_ctype = 0; _M_ctype = 0;
if (__builtin_expect(has_facet<__num_put_type>(__loc), true)) if (__builtin_expect(has_facet<__num_put_type>(__loc), true))
_M_num_put = &use_facet<__num_put_type>(__loc); _M_num_put = std::__addressof(use_facet<__num_put_type>(__loc));
else else
_M_num_put = 0; _M_num_put = 0;
if (__builtin_expect(has_facet<__num_get_type>(__loc), true)) if (__builtin_expect(has_facet<__num_get_type>(__loc), true))
_M_num_get = &use_facet<__num_get_type>(__loc); _M_num_get = std::__addressof(use_facet<__num_get_type>(__loc));
else else
_M_num_get = 0; _M_num_get = 0;
} }
......
...@@ -66,7 +66,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -66,7 +66,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// Construct start of input stream iterator. /// Construct start of input stream iterator.
istream_iterator(istream_type& __s) istream_iterator(istream_type& __s)
: _M_stream(&__s) : _M_stream(std::__addressof(__s))
{ _M_read(); } { _M_read(); }
istream_iterator(const istream_iterator& __obj) istream_iterator(const istream_iterator& __obj)
...@@ -84,7 +84,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -84,7 +84,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} }
const _Tp* const _Tp*
operator->() const { return &(operator*()); } operator->() const { return std::__addressof((operator*())); }
istream_iterator& istream_iterator&
operator++() operator++()
...@@ -168,7 +168,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -168,7 +168,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
public: public:
/// Construct from an ostream. /// Construct from an ostream.
ostream_iterator(ostream_type& __s) : _M_stream(&__s), _M_string(0) {} ostream_iterator(ostream_type& __s)
: _M_stream(std::__addressof(__s)), _M_string(0) {}
/** /**
* Construct from an ostream. * Construct from an ostream.
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#else #else
#include <bits/atomic_base.h> #include <bits/atomic_base.h>
#include <bits/move.h>
namespace std _GLIBCXX_VISIBILITY(default) namespace std _GLIBCXX_VISIBILITY(default)
{ {
...@@ -222,17 +223,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -222,17 +223,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void void
store(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept store(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept
{ __atomic_store(&_M_i, &__i, __m); } { __atomic_store(std::__addressof(_M_i), std::__addressof(__i), __m); }
void void
store(_Tp __i, memory_order __m = memory_order_seq_cst) volatile noexcept store(_Tp __i, memory_order __m = memory_order_seq_cst) volatile noexcept
{ __atomic_store(&_M_i, &__i, __m); } { __atomic_store(std::__addressof(_M_i), std::__addressof(__i), __m); }
_Tp _Tp
load(memory_order __m = memory_order_seq_cst) const noexcept load(memory_order __m = memory_order_seq_cst) const noexcept
{ {
_Tp tmp; _Tp tmp;
__atomic_load(&_M_i, &tmp, __m); __atomic_load(std::__addressof(_M_i), std::__addressof(tmp), __m);
return tmp; return tmp;
} }
...@@ -240,7 +241,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -240,7 +241,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
load(memory_order __m = memory_order_seq_cst) const volatile noexcept load(memory_order __m = memory_order_seq_cst) const volatile noexcept
{ {
_Tp tmp; _Tp tmp;
__atomic_load(&_M_i, &tmp, __m); __atomic_load(std::__addressof(_M_i), std::__addressof(tmp), __m);
return tmp; return tmp;
} }
...@@ -248,7 +249,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -248,7 +249,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
exchange(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept exchange(_Tp __i, memory_order __m = memory_order_seq_cst) noexcept
{ {
_Tp tmp; _Tp tmp;
__atomic_exchange(&_M_i, &__i, &tmp, __m); __atomic_exchange(std::__addressof(_M_i), std::__addressof(__i),
std::__addressof(tmp), __m);
return tmp; return tmp;
} }
...@@ -257,7 +259,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -257,7 +259,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
memory_order __m = memory_order_seq_cst) volatile noexcept memory_order __m = memory_order_seq_cst) volatile noexcept
{ {
_Tp tmp; _Tp tmp;
__atomic_exchange(&_M_i, &__i, &tmp, __m); __atomic_exchange(std::__addressof(_M_i), std::__addressof(__i),
std::__addressof(tmp), __m);
return tmp; return tmp;
} }
...@@ -265,14 +268,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -265,14 +268,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s, compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
memory_order __f) noexcept memory_order __f) noexcept
{ {
return __atomic_compare_exchange(&_M_i, &__e, &__i, true, __s, __f); return __atomic_compare_exchange(std::__addressof(_M_i),
std::__addressof(__e),
std::__addressof(__i),
true, __s, __f);
} }
bool bool
compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s, compare_exchange_weak(_Tp& __e, _Tp __i, memory_order __s,
memory_order __f) volatile noexcept memory_order __f) volatile noexcept
{ {
return __atomic_compare_exchange(&_M_i, &__e, &__i, true, __s, __f); return __atomic_compare_exchange(std::__addressof(_M_i),
std::__addressof(__e),
std::__addressof(__i),
true, __s, __f);
} }
bool bool
...@@ -291,14 +300,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -291,14 +300,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s, compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s,
memory_order __f) noexcept memory_order __f) noexcept
{ {
return __atomic_compare_exchange(&_M_i, &__e, &__i, false, __s, __f); return __atomic_compare_exchange(std::__addressof(_M_i),
std::__addressof(__e),
std::__addressof(__i),
false, __s, __f);
} }
bool bool
compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s, compare_exchange_strong(_Tp& __e, _Tp __i, memory_order __s,
memory_order __f) volatile noexcept memory_order __f) volatile noexcept
{ {
return __atomic_compare_exchange(&_M_i, &__e, &__i, false, __s, __f); return __atomic_compare_exchange(std::__addressof(_M_i),
std::__addressof(__e),
std::__addressof(__i),
false, __s, __f);
} }
bool bool
......
...@@ -550,27 +550,30 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -550,27 +550,30 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
shared_lock() noexcept : _M_pm(nullptr), _M_owns(false) { } shared_lock() noexcept : _M_pm(nullptr), _M_owns(false) { }
explicit explicit
shared_lock(mutex_type& __m) : _M_pm(&__m), _M_owns(true) shared_lock(mutex_type& __m)
: _M_pm(std::__addressof(__m)), _M_owns(true)
{ __m.lock_shared(); } { __m.lock_shared(); }
shared_lock(mutex_type& __m, defer_lock_t) noexcept shared_lock(mutex_type& __m, defer_lock_t) noexcept
: _M_pm(&__m), _M_owns(false) { } : _M_pm(std::__addressof(__m)), _M_owns(false) { }
shared_lock(mutex_type& __m, try_to_lock_t) shared_lock(mutex_type& __m, try_to_lock_t)
: _M_pm(&__m), _M_owns(__m.try_lock_shared()) { } : _M_pm(std::__addressof(__m)), _M_owns(__m.try_lock_shared()) { }
shared_lock(mutex_type& __m, adopt_lock_t) shared_lock(mutex_type& __m, adopt_lock_t)
: _M_pm(&__m), _M_owns(true) { } : _M_pm(std::__addressof(__m)), _M_owns(true) { }
template<typename _Clock, typename _Duration> template<typename _Clock, typename _Duration>
shared_lock(mutex_type& __m, shared_lock(mutex_type& __m,
const chrono::time_point<_Clock, _Duration>& __abs_time) const chrono::time_point<_Clock, _Duration>& __abs_time)
: _M_pm(&__m), _M_owns(__m.try_lock_shared_until(__abs_time)) { } : _M_pm(std::__addressof(__m)),
_M_owns(__m.try_lock_shared_until(__abs_time)) { }
template<typename _Rep, typename _Period> template<typename _Rep, typename _Period>
shared_lock(mutex_type& __m, shared_lock(mutex_type& __m,
const chrono::duration<_Rep, _Period>& __rel_time) const chrono::duration<_Rep, _Period>& __rel_time)
: _M_pm(&__m), _M_owns(__m.try_lock_shared_for(__rel_time)) { } : _M_pm(std::__addressof(__m)),
_M_owns(__m.try_lock_shared_for(__rel_time)) { }
~shared_lock() ~shared_lock()
{ {
......
// Copyright (C) 2016 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 <iterator>
#include <istream>
namespace adl
{
template<typename T>
void operator&(const T&) = delete;
struct traits : std::char_traits<char> { };
struct X { void f() const { } };
std::basic_istream<char, adl::traits>&
operator>>(std::basic_istream<char, adl::traits>& is, X&)
{ return is; }
}
void
test01()
{
std::basic_istream<char, adl::traits> is(nullptr);
std::istream_iterator<adl::X, char, adl::traits> ii(is);
ii->f();
}
// Copyright (C) 2016 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 <iterator>
#include <ostream>
namespace adl
{
template<typename T>
void operator&(const T&) = delete;
struct traits : std::char_traits<char> { };
}
void
test01()
{
std::basic_ostream<char, adl::traits> os(nullptr);
std::ostream_iterator<int, char, adl::traits> oi(os);
}
...@@ -27,4 +27,4 @@ struct X { ...@@ -27,4 +27,4 @@ struct X {
char stuff[0]; // GNU extension, type has zero size char stuff[0]; // GNU extension, type has zero size
}; };
std::atomic<X> a; // { dg-error "not supported" "" { target *-*-* } 181 } std::atomic<X> a; // { dg-error "not supported" "" { target *-*-* } 182 }
// Copyright (C) 2016 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 <atomic>
namespace adl
{
template<typename T>
void operator&(const T&) = delete;
struct X {
int i;
};
}
void
test01()
{
adl::X x;
std::atomic<adl::X> a;
a.store(x);
x = a.load();
x = a.exchange(x);
a.compare_exchange_weak(x, x);
a.compare_exchange_strong(x, x);
}
void
test02()
{
adl::X x;
volatile std::atomic<adl::X> a;
a.store(x);
x = a.load();
x = a.exchange(x);
a.compare_exchange_weak(x, x);
a.compare_exchange_strong(x, x);
}
// Copyright (C) 2016 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++17" }
// { dg-do compile }
#include <shared_mutex>
namespace adl
{
template<typename T>
void operator&(const T&) = delete;
struct M : std::shared_timed_mutex { };
}
void
test01()
{
using namespace std::chrono_literals;
adl::M m;
std::shared_lock<adl::M> l1(m);
std::shared_lock<adl::M> l2(m, std::defer_lock);
std::shared_lock<adl::M> l3(m, std::try_to_lock);
m.lock_shared();
std::shared_lock<adl::M> l4(m, std::adopt_lock);
std::shared_lock<adl::M> l5(m, std::chrono::system_clock::now() + 1ms);
std::shared_lock<adl::M> l6(m, 1ms);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment