From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 15DB3385841F; Thu, 29 Jun 2023 23:00:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 15DB3385841F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688079659; bh=zF+PGirPrNHnh6KH1/NZSaxegY61V9Q5tentp/Wc894=; h=From:To:Subject:Date:From; b=g16vX+JMnKCiHv8WvttCteyt1dD4Tm0EnjSO+H0a9/mDF9O7vOUhvs1NAMSN7Zb6V aELib/VNsS5X2fGGqlBeDrnNmOHG+dwoyWRRuWGaDjmR0y8Sk4bjJqZ+UO16bSz2z4 vrcP84RDGsdX1cE/jbV1pv6fqq4wUsJsk54+1ino= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-7506] libstdc++: Add missing noexcept to std::scoped_allocator_adaptor X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: 52997b14311726447850341ecaf286b68587ff32 X-Git-Newrev: 4b05a7d051a0013e984c844baf328e79c9fa6cff Message-Id: <20230629230059.15DB3385841F@sourceware.org> Date: Thu, 29 Jun 2023 23:00:59 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4b05a7d051a0013e984c844baf328e79c9fa6cff commit r13-7506-g4b05a7d051a0013e984c844baf328e79c9fa6cff Author: Jonathan Wakely Date: Fri May 26 21:33:58 2023 +0100 libstdc++: Add missing noexcept to std::scoped_allocator_adaptor The standard requires these constructors and accessors to be noexcept. libstdc++-v3/ChangeLog: * include/std/scoped_allocator (scoped_allocator_adaptor): Add noexcept to all constructors except the default constructor. (scoped_allocator_adaptor::inner_allocator): Add noexcept. (scoped_allocator_adaptor::outer_allocator): Likewise. * testsuite/20_util/scoped_allocator/noexcept.cc: New test. (cherry picked from commit b960c253e988c68ed3f3829125bc267bdf169356) Diff: --- libstdc++-v3/include/std/scoped_allocator | 45 ++++++++++++--------- .../testsuite/20_util/scoped_allocator/noexcept.cc | 47 ++++++++++++++++++++++ 2 files changed, 73 insertions(+), 19 deletions(-) diff --git a/libstdc++-v3/include/std/scoped_allocator b/libstdc++-v3/include/std/scoped_allocator index 68e6afb1000..a11545026ba 100644 --- a/libstdc++-v3/include/std/scoped_allocator +++ b/libstdc++-v3/include/std/scoped_allocator @@ -65,7 +65,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __outermost_type { using type = _Alloc; - static type& _S_outermost(_Alloc& __a) { return __a; } + static type& _S_outermost(_Alloc& __a) noexcept { return __a; } }; template @@ -79,7 +79,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION >; static typename __base::type& - _S_outermost(_Alloc& __a) + _S_outermost(_Alloc& __a) noexcept { return __base::_S_outermost(__a.outer_allocator()); } }; @@ -104,11 +104,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __inner_type_impl& operator=(__inner_type_impl&&) = default; template - __inner_type_impl(const __inner_type_impl<_Alloc>& __other) + __inner_type_impl(const __inner_type_impl<_Alloc>& __other) noexcept { } template - __inner_type_impl(__inner_type_impl<_Alloc>&& __other) + __inner_type_impl(__inner_type_impl<_Alloc>&& __other) noexcept { } __type& @@ -137,16 +137,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __inner_type_impl& operator=(__inner_type_impl&&) = default; template - __inner_type_impl(const __inner_type_impl<_Allocs...>& __other) + __inner_type_impl(const __inner_type_impl<_Allocs...>& __other) noexcept : _M_inner(__other._M_inner) { } template - __inner_type_impl(__inner_type_impl<_Allocs...>&& __other) + __inner_type_impl(__inner_type_impl<_Allocs...>&& __other) noexcept : _M_inner(std::move(__other._M_inner)) { } template explicit - __inner_type_impl(_Args&&... __args) + __inner_type_impl(_Args&&... __args) noexcept : _M_inner(std::forward<_Args>(__args)...) { } __type& @@ -307,31 +307,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template> scoped_allocator_adaptor(_Outer2&& __outer, - const _InnerAllocs&... __inner) + const _InnerAllocs&... __inner) noexcept : _OuterAlloc(std::forward<_Outer2>(__outer)), _M_inner(__inner...) { } - scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) + scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) noexcept : _OuterAlloc(__other.outer_allocator()), _M_inner(__other._M_inner) { } - scoped_allocator_adaptor(scoped_allocator_adaptor&& __other) + scoped_allocator_adaptor(scoped_allocator_adaptor&& __other) noexcept : _OuterAlloc(std::move(__other.outer_allocator())), _M_inner(std::move(__other._M_inner)) { } template> scoped_allocator_adaptor( - const scoped_allocator_adaptor<_Outer2, _InnerAllocs...>& __other) + const scoped_allocator_adaptor<_Outer2, _InnerAllocs...>& __other + ) noexcept : _OuterAlloc(__other.outer_allocator()), _M_inner(__other._M_inner) { } template> scoped_allocator_adaptor( - scoped_allocator_adaptor<_Outer2, _InnerAllocs...>&& __other) + scoped_allocator_adaptor<_Outer2, _InnerAllocs...>&& __other) noexcept : _OuterAlloc(std::move(__other.outer_allocator())), _M_inner(std::move(__other._M_inner)) { } @@ -342,25 +343,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default; - inner_allocator_type& inner_allocator() noexcept + inner_allocator_type& + inner_allocator() noexcept { return _M_inner._M_get(this); } - const inner_allocator_type& inner_allocator() const noexcept + const inner_allocator_type& + inner_allocator() const noexcept { return _M_inner._M_get(this); } - outer_allocator_type& outer_allocator() noexcept + outer_allocator_type& + outer_allocator() noexcept { return static_cast<_OuterAlloc&>(*this); } - const outer_allocator_type& outer_allocator() const noexcept + const outer_allocator_type& + outer_allocator() const noexcept { return static_cast(*this); } - _GLIBCXX_NODISCARD pointer allocate(size_type __n) + _GLIBCXX_NODISCARD pointer + allocate(size_type __n) { return __traits::allocate(outer_allocator(), __n); } - _GLIBCXX_NODISCARD pointer allocate(size_type __n, const_void_pointer __hint) + _GLIBCXX_NODISCARD pointer + allocate(size_type __n, const_void_pointer __hint) { return __traits::allocate(outer_allocator(), __n, __hint); } - void deallocate(pointer __p, size_type __n) + void deallocate(pointer __p, size_type __n) noexcept { return __traits::deallocate(outer_allocator(), __p, __n); } size_type max_size() const diff --git a/libstdc++-v3/testsuite/20_util/scoped_allocator/noexcept.cc b/libstdc++-v3/testsuite/20_util/scoped_allocator/noexcept.cc new file mode 100644 index 00000000000..16992968d3b --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/scoped_allocator/noexcept.cc @@ -0,0 +1,47 @@ +// { dg-do compile { target c++11 } } + +#include + +template +struct Alloc +{ + using value_type = T; + + Alloc() noexcept(false) { } + Alloc(const Alloc&) noexcept(false) { } + template Alloc(const Alloc&) noexcept { } + + T* allocate(std::size_t); + void deallocate(T*, std::size_t); + + bool operator==(const Alloc&) const noexcept(false) { return true; } + bool operator!=(const Alloc&) const noexcept(false) { return false; } +}; + +using A1 = std::allocator; +using A2 = std::allocator; +using Ax = Alloc; +using SA1 = std::scoped_allocator_adaptor; +using SA2 = std::scoped_allocator_adaptor; +static_assert( std::is_default_constructible::value + && ! std::is_nothrow_default_constructible::value, + "default constructor is potentially-throwing" ); +static_assert( std::is_nothrow_constructible::value, + "multi-arg constructor is non-throwing" ); +static_assert( std::is_nothrow_copy_constructible::value, + "copy constructor is non-throwing" ); +static_assert( std::is_nothrow_move_constructible::value, + "move constructor is non-throwing" ); +static_assert( std::is_nothrow_constructible::value, + "converting copy constructor is non-throwing" ); +static_assert( std::is_nothrow_constructible::value, + "converting move constructor is non-throwing" ); + +static_assert( noexcept(std::declval().inner_allocator()), + "inner_allocator() is non-throwing" ); +static_assert( noexcept(std::declval().inner_allocator()), + "inner_allocator() const is non-throwing" ); +static_assert( noexcept(std::declval().outer_allocator()), + "outer_allocator() is non-throwing" ); +static_assert( noexcept(std::declval().outer_allocator()), + "outer_allocator() const is non-throwing" );