From f885fa898fdf8dc53081d584e322f5d9af3491a3 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 7 Jan 2016 15:01:33 +0000 Subject: [PATCH] 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 --- libstdc++-v3/ChangeLog | 15 +++++++ libstdc++-v3/include/bits/stl_iterator.h | 8 ++-- libstdc++-v3/include/bits/uses_allocator.h | 2 +- libstdc++-v3/include/std/future | 2 +- libstdc++-v3/include/std/scoped_allocator | 7 +-- .../testsuite/20_util/scoped_allocator/69114.cc | 50 ++++++++++++++++++++++ .../testsuite/20_util/uses_allocator/69114.cc | 49 +++++++++++++++++++++ libstdc++-v3/testsuite/30_threads/promise/69106.cc | 34 +++++++++++++++ 8 files changed, 159 insertions(+), 8 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/scoped_allocator/69114.cc create mode 100644 libstdc++-v3/testsuite/20_util/uses_allocator/69114.cc create mode 100644 libstdc++-v3/testsuite/30_threads/promise/69106.cc 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 + + 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 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 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 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 @@ -61,8 +61,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // TODO: make recursive (see note in 20.12.4/1) template 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 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 +// . + +// { dg-do compile } +// { dg-options "-std=gnu++11" } + +// PR libstdc++/69114 + +#include + +template +struct Alloc +{ + using value_type = T; + + Alloc() = default; + + template + Alloc(const Alloc&) { } + + 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::scoped_allocator_adaptor 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 +// . + +// { dg-do compile } +// { dg-options "-std=gnu++11" } + +// PR libstdc++/69114 + +#include + +template +struct Alloc +{ + using value_type = T; + + Alloc() = default; + + template + Alloc(const Alloc&) { } + + 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 a; + std::tuple 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 +// . + +// { dg-do compile } +// { dg-options "-std=gnu++11" } +// { dg-require-cstdint "" } +// { dg-require-gthreads "" } +// { dg-require-atomic-builtins "" } + +#include + +struct foo { + void operator&() const = delete; +}; + +void test01() +{ + std::promise p; + p.set_value(foo()); +} -- 2.7.4