From patchwork Fri Sep 16 22:33:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1271 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp955521wrt; Fri, 16 Sep 2022 15:36:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4WyjPJ+zq7G+7PAf2fu4kmt4WLDBJPoukfIJq93llbhUSGS5+J/AqrUkIPRkarDNMlRq9I X-Received: by 2002:a17:907:70a:b0:741:78ab:dce5 with SMTP id xb10-20020a170907070a00b0074178abdce5mr5057831ejb.527.1663367771031; Fri, 16 Sep 2022 15:36:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663367771; cv=none; d=google.com; s=arc-20160816; b=uS6e+YJkpZjxMTI1F3RLGAuZwGQ1hZE1f1t+6TbKQxWPPyARwTkDPMAXfxJ6cyiKA+ B0GqctDZkO9oUFgBnyjAOkl+7Yn+wulE4Io4bJSC3mF5oLsc5pG1GrpSthEsu5S+FXxt Lsj0/1aREKG9wosYmL3V3E8QmqllyFfqFATePtLyzUSZskQkjhAUbEyyI9wnEDGg6qNp jdtHkWNeGShexFtyaHRSrhEtwCi+ZiZuOBKcjJjFV3cIKZPJnQ6WQKkoKOTffJMukkzg +O8p+Y6c7jx5fFXMOTlyMt2/S3lt486UjOnVWlIJBJk1xYoGI6LV00tHug24HByR45ra epLg== 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=AmJFuMhfdWexRcSzx4eIPXMOuX1utAej/fa/qsrA8dM=; b=0BsoSFwqF0rJaRGCYOiOKcnBaT0/gCMW6E1r4w8gZlJS78MSP/pH9WYAXw0Ld5wJSJ ZwIIkW0wDAGcbGVDCAhUBZjY5YRX7+m0AONmBEilEwC5TkYa3lgDieoCNoq5GDy6Iz3H 7on00fcOfmxtb0cU7sqcr3OJapIjlsdBydsNTg7i8klGMaebXc31WWQOzLNgoTiEdqCV PfTTHOSmcGB52viAySEwt5ZJ7aBAtQ+Ydm0np9pl5HVW+RE/zihGnnzNGph9itf56ukj /R0dGNE4tXLljwF9H3+v+8FOYaF8hjxuN/M+G7PvwzsCwd5RafZYMkRBYNSWnVS2Pd09 Mk7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Y4S1GQEN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j12-20020aa7ca4c000000b0044e8b287219si2898090edt.179.2022.09.16.15.36.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 15:36:11 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Y4S1GQEN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 C0C8D38A816C for ; Fri, 16 Sep 2022 22:36:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C0C8D38A816C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663367762; bh=AmJFuMhfdWexRcSzx4eIPXMOuX1utAej/fa/qsrA8dM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Y4S1GQENmDf9jNKkAFoFdKlJQVlfwj5CYLaAdwN4++KSAGCgSylu9jr9hjvi7h/MW S+kOQx20UVW97UMknWZDuE62wWh8d3cC3uGNdBaWpGMYg5cVrSVuuV56PyQgGJdkUV PxiI0/D/87zsu0i278VGN/mKamnEMsRPzt4xRb6Y= 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 1EA8C3857C71 for ; Fri, 16 Sep 2022 22:33:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1EA8C3857C71 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-99-dBv9aoFZNomlgV-4XG9Irw-1; Fri, 16 Sep 2022 18:33:48 -0400 X-MC-Unique: dBv9aoFZNomlgV-4XG9Irw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4E9BA185A792; Fri, 16 Sep 2022 22:33:48 +0000 (UTC) Received: from localhost (unknown [10.33.36.214]) by smtp.corp.redhat.com (Postfix) with ESMTP id 168AB477F55; Fri, 16 Sep 2022 22:33:47 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Move allocator-related helpers to Date: Fri, 16 Sep 2022 23:33:47 +0100 Message-Id: <20220916223347.602295-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP 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?1744167523956627712?= X-GMAIL-MSGID: =?utf-8?q?1744167523956627712?= Tested x86_64-linux, pushed to trunk. -- >8 -- The __alloc_swap and __shrink_to_fit_aux helpers are not specific to std::allocator, so don't belong in . This also simplifies enabling for freestanding, as now we can just omit the whole of for freestanding. libstdc++-v3/ChangeLog: * include/bits/alloc_traits.h (__alloc_swap) (__shrink_to_fit_aux): Move here, from ... * include/bits/allocator.h: ... here. * include/ext/alloc_traits.h: Do not include allocator.h. --- libstdc++-v3/include/bits/alloc_traits.h | 48 ++++++++++++++++++++++ libstdc++-v3/include/bits/allocator.h | 51 ------------------------ libstdc++-v3/include/ext/alloc_traits.h | 3 -- 3 files changed, 48 insertions(+), 54 deletions(-) diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h index f9ca37fd7d6..35bdf6ecf98 100644 --- a/libstdc++-v3/include/bits/alloc_traits.h +++ b/libstdc++-v3/include/bits/alloc_traits.h @@ -824,6 +824,54 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// @cond undocumented + // To implement Option 3 of DR 431. + template + struct __alloc_swap + { static void _S_do_it(_Alloc&, _Alloc&) _GLIBCXX_NOEXCEPT { } }; + + template + struct __alloc_swap<_Alloc, false> + { + static void + _S_do_it(_Alloc& __one, _Alloc& __two) _GLIBCXX_NOEXCEPT + { + // Precondition: swappable allocators. + if (__one != __two) + swap(__one, __two); + } + }; + +#if __cplusplus >= 201103L + template, + is_nothrow_move_constructible>::value> + struct __shrink_to_fit_aux + { static bool _S_do_it(_Tp&) noexcept { return false; } }; + + template + struct __shrink_to_fit_aux<_Tp, true> + { + _GLIBCXX20_CONSTEXPR + static bool + _S_do_it(_Tp& __c) noexcept + { +#if __cpp_exceptions + try + { + _Tp(__make_move_if_noexcept_iterator(__c.begin()), + __make_move_if_noexcept_iterator(__c.end()), + __c.get_allocator()).swap(__c); + return true; + } + catch(...) + { return false; } +#else + return false; +#endif + } + }; +#endif + /** * Destroy a range of objects using the supplied allocator. For * non-default allocators we do not optimize away invocation of diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h index c39166e24fe..54f5acf85d7 100644 --- a/libstdc++-v3/include/bits/allocator.h +++ b/libstdc++-v3/include/bits/allocator.h @@ -279,57 +279,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Undefine. #undef __allocator_base - /// @cond undocumented - - // To implement Option 3 of DR 431. - template - struct __alloc_swap - { static void _S_do_it(_Alloc&, _Alloc&) _GLIBCXX_NOEXCEPT { } }; - - template - struct __alloc_swap<_Alloc, false> - { - static void - _S_do_it(_Alloc& __one, _Alloc& __two) _GLIBCXX_NOEXCEPT - { - // Precondition: swappable allocators. - if (__one != __two) - swap(__one, __two); - } - }; - -#if __cplusplus >= 201103L - template, - is_nothrow_move_constructible>::value> - struct __shrink_to_fit_aux - { static bool _S_do_it(_Tp&) noexcept { return false; } }; - - template - struct __shrink_to_fit_aux<_Tp, true> - { - _GLIBCXX20_CONSTEXPR - static bool - _S_do_it(_Tp& __c) noexcept - { -#if __cpp_exceptions - try - { - _Tp(__make_move_if_noexcept_iterator(__c.begin()), - __make_move_if_noexcept_iterator(__c.end()), - __c.get_allocator()).swap(__c); - return true; - } - catch(...) - { return false; } -#else - return false; -#endif - } - }; -#endif - /// @endcond - _GLIBCXX_END_NAMESPACE_VERSION } // namespace std diff --git a/libstdc++-v3/include/ext/alloc_traits.h b/libstdc++-v3/include/ext/alloc_traits.h index 1d7d9598cb2..c9547c7305c 100644 --- a/libstdc++-v3/include/ext/alloc_traits.h +++ b/libstdc++-v3/include/ext/alloc_traits.h @@ -32,9 +32,6 @@ #pragma GCC system_header # include -#if __cplusplus < 201103L -# include // for __alloc_swap -#endif namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) {