diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2016-01-07 15:01:33 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2016-01-07 15:01:33 +0000 |
commit | f885fa898fdf8dc53081d584e322f5d9af3491a3 (patch) | |
tree | 30850f33b00dc6cf6fb619896993a9ff8417f621 | |
parent | 64d3ef31dffb75b1a16837564eac5b613d49cafc (diff) | |
download | gcc-f885fa898fdf8dc53081d584e322f5d9af3491a3.zip gcc-f885fa898fdf8dc53081d584e322f5d9af3491a3.tar.gz gcc-f885fa898fdf8dc53081d584e322f5d9af3491a3.tar.bz2 |
Use std::addressof in insert iterators, allocators and promises
PR libstdc++/69105
PR libstdc++/69106
PR libstdc++/69114
* include/bits/stl_iterator.h (back_insert_iterator,
front_insert_iterator, insert_iterator): Use __addressof (LWG 2324).
* include/bits/uses_allocator.h (__use_alloc): Use __addressof.
* include/std/future (__future::base::_State_baseV2::__setter):
Likewise.
* include/std/scoped_allocator (__outermost): Likewise.
* testsuite/20_util/scoped_allocator/69114.cc: New.
* testsuite/20_util/uses_allocator/69114.cc: New.
* testsuite/30_threads/promise/69106.cc: New.
From-SVN: r232129
-rw-r--r-- | libstdc++-v3/ChangeLog | 15 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_iterator.h | 8 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/uses_allocator.h | 2 | ||||
-rw-r--r-- | libstdc++-v3/include/std/future | 2 | ||||
-rw-r--r-- | libstdc++-v3/include/std/scoped_allocator | 7 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/scoped_allocator/69114.cc | 50 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/uses_allocator/69114.cc | 49 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/30_threads/promise/69106.cc | 34 |
8 files changed, 159 insertions, 8 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6c5b641..782bae9 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,18 @@ +2016-01-07 Jonathan Wakely <jwakely@redhat.com> + + PR libstdc++/69105 + PR libstdc++/69106 + PR libstdc++/69114 + * include/bits/stl_iterator.h (back_insert_iterator, + front_insert_iterator, insert_iterator): Use __addressof (LWG 2324). + * include/bits/uses_allocator.h (__use_alloc): Use __addressof. + * include/std/future (__future::base::_State_baseV2::__setter): + Likewise. + * include/std/scoped_allocator (__outermost): Likewise. + * testsuite/20_util/scoped_allocator/69114.cc: New. + * testsuite/20_util/uses_allocator/69114.cc: New. + * testsuite/30_threads/promise/69106.cc: New. + 2016-01-06 Jonathan Wakely <jwakely@redhat.com> PR libstdc++/69092 diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index c86bec3..3401cd0 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -451,7 +451,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// The only way to create this %iterator is with a container. explicit - back_insert_iterator(_Container& __x) : container(&__x) { } + back_insert_iterator(_Container& __x) + : container(std::__addressof(__x)) { } /** * @param __value An instance of whatever type @@ -541,7 +542,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef _Container container_type; /// The only way to create this %iterator is with a container. - explicit front_insert_iterator(_Container& __x) : container(&__x) { } + explicit front_insert_iterator(_Container& __x) + : container(std::__addressof(__x)) { } /** * @param __value An instance of whatever type @@ -640,7 +642,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * initial position (a normal %iterator into the container). */ insert_iterator(_Container& __x, typename _Container::iterator __i) - : container(&__x), iter(__i) {} + : container(std::__addressof(__x)), iter(__i) {} /** * @param __value An instance of whatever type diff --git a/libstdc++-v3/include/bits/uses_allocator.h b/libstdc++-v3/include/bits/uses_allocator.h index 660a64e..b3c3f60 100644 --- a/libstdc++-v3/include/bits/uses_allocator.h +++ b/libstdc++-v3/include/bits/uses_allocator.h @@ -99,7 +99,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __use_alloc(const _Alloc& __a) { __uses_alloc_t<_Tp, _Alloc, _Args...> __ret; - __ret._M_a = &__a; + __ret._M_a = std::__addressof(__a); return __ret; } diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future index d2ac68b..80b7b06 100644 --- a/libstdc++-v3/include/std/future +++ b/libstdc++-v3/include/std/future @@ -507,7 +507,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static _Setter<_Res, _Arg&&> __setter(promise<_Res>* __prom, _Arg&& __arg) { - return _Setter<_Res, _Arg&&>{ __prom, &__arg }; + return _Setter<_Res, _Arg&&>{ __prom, std::__addressof(__arg) }; } template<typename _Res> diff --git a/libstdc++-v3/include/std/scoped_allocator b/libstdc++-v3/include/std/scoped_allocator index c30ec7c..aac2dfe 100644 --- a/libstdc++-v3/include/std/scoped_allocator +++ b/libstdc++-v3/include/std/scoped_allocator @@ -50,7 +50,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Alloc> inline auto - __do_outermost(_Alloc& __a, _Alloc*) -> decltype(__a.outer_allocator()) + __do_outermost(_Alloc& __a, int) -> decltype(__a.outer_allocator()) { return __a.outer_allocator(); } template<typename _Alloc> @@ -61,8 +61,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // TODO: make recursive (see note in 20.12.4/1) template<typename _Alloc> inline auto - __outermost(_Alloc& __a) -> decltype(__do_outermost(__a, &__a)) - { return __do_outermost(__a, &__a); } + __outermost(_Alloc& __a) + -> decltype(__do_outermost(__a, 0)) + { return __do_outermost(__a, 0); } template<typename _OuterAlloc, typename... _InnerAllocs> class scoped_allocator_adaptor; diff --git a/libstdc++-v3/testsuite/20_util/scoped_allocator/69114.cc b/libstdc++-v3/testsuite/20_util/scoped_allocator/69114.cc new file mode 100644 index 0000000..6890d18 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/scoped_allocator/69114.cc @@ -0,0 +1,50 @@ +// 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-do compile } +// { dg-options "-std=gnu++11" } + +// PR libstdc++/69114 + +#include <scoped_allocator> + +template<typename T> +struct Alloc +{ + using value_type = T; + + Alloc() = default; + + template<typename U> + Alloc(const Alloc<U>&) { } + + T* allocate(std::size_t); + void deallocate(T*, std::size_t); + + bool operator==(const Alloc&) const { return true; } + bool operator!=(const Alloc&) const { return false; } + + void operator&() = delete; +}; + +void +test01() +{ + using alloc_type = Alloc<std::pair<int, int>>; + std::scoped_allocator_adaptor<alloc_type> a; + a.construct(a.allocate(1)); +} diff --git a/libstdc++-v3/testsuite/20_util/uses_allocator/69114.cc b/libstdc++-v3/testsuite/20_util/uses_allocator/69114.cc new file mode 100644 index 0000000..0ab7ed3 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/uses_allocator/69114.cc @@ -0,0 +1,49 @@ +// 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-do compile } +// { dg-options "-std=gnu++11" } + +// PR libstdc++/69114 + +#include <tuple> + +template<typename T> +struct Alloc +{ + using value_type = T; + + Alloc() = default; + + template<typename U> + Alloc(const Alloc<U>&) { } + + T* allocate(std::size_t); + void deallocate(T*, std::size_t); + + bool operator==(const Alloc&) const { return true; } + bool operator!=(const Alloc&) const { return false; } + + void operator&() = delete; +}; + +void +test01() +{ + Alloc<int> a; + std::tuple<int> t(std::allocator_arg, a); +} diff --git a/libstdc++-v3/testsuite/30_threads/promise/69106.cc b/libstdc++-v3/testsuite/30_threads/promise/69106.cc new file mode 100644 index 0000000..921ded1 --- /dev/null +++ b/libstdc++-v3/testsuite/30_threads/promise/69106.cc @@ -0,0 +1,34 @@ +// 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-do compile } +// { dg-options "-std=gnu++11" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +#include <future> + +struct foo { + void operator&() const = delete; +}; + +void test01() +{ + std::promise<foo> p; + p.set_value(foo()); +} |