From patchwork Wed May 31 12:22:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 101405 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2838989vqr; Wed, 31 May 2023 05:26:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5WtoGMZ+8WCQ+xtvkffA0rie7haGY13Zt/oyKz96keA/uuo6xMPZBKa1tgySfiyt6UddQr X-Received: by 2002:a50:fb8d:0:b0:514:a32c:ee36 with SMTP id e13-20020a50fb8d000000b00514a32cee36mr3924802edq.0.1685535996208; Wed, 31 May 2023 05:26:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685535996; cv=none; d=google.com; s=arc-20160816; b=oQgPGXzyEBdF3O1RxuD7klgcNv9/VLK8avzRk0Nw8ifjW8Y8i+HTz0f6fQY2UkFjgE XF+YBMabEdc/fyfbPYzwuTuFOC21wOi8GcF6T5OuarxWhlsGjYIyt7pgyMChJVYlV0Cg dgfz4ikrT/hbQyCIZvoQgvAr4HSmUXBqz4bkIAYX5Iuz6NocpcdtqfLcgJFQ0FZdnitC oxNEA+Vm5G4jGdWRF67LWWv1xmQOz8JP3LZezJzqWIRJW8aD+OcpFCb1tZvY1lzIPIn3 hNucCSjhgIVdq6J/CuCdVU52NN+qVMs6HrMoX6dqnBad+kjJIvgdu/djRcuOiEiSjXJj KEZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=zX7Edwhc4DBqT9Y1Uh7xOlI6qaCWZ8TdJ0LAT6CjJnc=; b=vjNURVIp/fW7kB+fB4cUmdhN9/vK0lUBxgIu9xNI+v4dZGxwsr7EacxW7f/et82pkL 14Ps6dzqTWVo9CwGPHgFpwH6JuqZed2KYXMRxruY82B+WzZkWpnKzvF0+51FKtpYg8Hp BDyPz1LdxZeuB/PxWM+bKBmCbkfPDB8GVL7LSidX7cvCalIxIRU+u32YKz+Ry/ajY2ez FoXVZkBFoxGQ6F8W0aK2/e93glz0iSi0bEMcVi5fL/a6ozIf0Ut+a/8IDlEPkmH1QWwL a8YRFJfzMUW46Oj8tzFYKkmGBj+G6W4YzGR1dIFO4MqUZ1tyXs747+imugyb6axa4ALp HkDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Wy+jbp+A; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b14-20020aa7c6ce000000b00514a23e7f0fsi4542648eds.485.2023.05.31.05.26.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 05:26:36 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Wy+jbp+A; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C95DD384646E for ; Wed, 31 May 2023 12:24:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C95DD384646E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685535847; bh=zX7Edwhc4DBqT9Y1Uh7xOlI6qaCWZ8TdJ0LAT6CjJnc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Wy+jbp+ANzqNFkhmM2bpY+0BaEZZcA1ZaG38NUsokzaQyV+0lxhiDKNfPnybQX88j SHDGFbYmeOZHqWAQsiISAumR/Qe38nBDVqYh406ovCMTJIFZDHq2RjDjXXynzlrUZB AYxG5HKtZMjvob6J4ijIzG6DcCupnXEmv8BdhXW8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id F1CCE385701E for ; Wed, 31 May 2023 12:22:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F1CCE385701E Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-191-qlVyurXgOCO7q6AT7taOlA-1; Wed, 31 May 2023 08:22:49 -0400 X-MC-Unique: qlVyurXgOCO7q6AT7taOlA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 33635101AA6D; Wed, 31 May 2023 12:22:49 +0000 (UTC) Received: from localhost (unknown [10.42.28.139]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9CD8492B0A; Wed, 31 May 2023 12:22:48 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add missing noexcept to std::scoped_allocator_adaptor Date: Wed, 31 May 2023 13:22:48 +0100 Message-Id: <20230531122248.4117478-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767412592630609134?= X-GMAIL-MSGID: =?utf-8?q?1767412592630609134?= Tested powerpc64le-linux. Pushed to trunk. -- >8 -- 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. --- libstdc++-v3/include/std/scoped_allocator | 45 ++++++++++-------- .../20_util/scoped_allocator/noexcept.cc | 47 +++++++++++++++++++ 2 files changed, 73 insertions(+), 19 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/scoped_allocator/noexcept.cc 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" );