From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 3D9B53858430; Mon, 18 Mar 2024 14:05:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D9B53858430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710770711; bh=x/MEIsxwtIEBBjC+FEnD1ktUIvC/2ZReXUwnAbUB3wo=; h=From:To:Subject:Date:From; b=g7zt0MAban02rtzIcHTW2bACYtvzh3lMls9M1i2sGk9D8Y4v0VK+xstaANYaVU2nQ zMQkRv6vyUwvGJmMxLxZqsWOyUYoYRkLOnASqaLmCEC0oSvout1RRhOgCBbqC4cIO9 jeRm1cq/35nHdkO7nrwxAp2kE8u95JYezGUso1mg= 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 r12-10242] 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-12 X-Git-Oldrev: ceb82ba594a6c24f33351eda0ae3fbb6fd6d841a X-Git-Newrev: 65704fa293ca9d5f9186aa09037fc2869492973b Message-Id: <20240318140511.3D9B53858430@sourceware.org> Date: Mon, 18 Mar 2024 14:05:11 +0000 (GMT) List-Id: https://gcc.gnu.org/g:65704fa293ca9d5f9186aa09037fc2869492973b commit r12-10242-g65704fa293ca9d5f9186aa09037fc2869492973b 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 8ad4c90b694..dd00e8efdbb 100644 --- a/libstdc++-v3/include/std/scoped_allocator +++ b/libstdc++-v3/include/std/scoped_allocator @@ -66,7 +66,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 @@ -80,7 +80,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()); } }; @@ -105,11 +105,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& @@ -138,16 +138,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& @@ -308,31 +308,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)) { } @@ -343,25 +344,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" );