From patchwork Fri Nov 17 14:48:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 166240 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp637813vqn; Fri, 17 Nov 2023 08:09:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFM+BoNWC+AtgjBzxRVJvxuQGdHtratJoTQTXnpdIBzWFbGehir1nlb+fQFQUJuV9LUDuQe X-Received: by 2002:a05:622a:410:b0:418:af4c:1853 with SMTP id n16-20020a05622a041000b00418af4c1853mr18165qtx.25.1700237344848; Fri, 17 Nov 2023 08:09:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700237344; cv=pass; d=google.com; s=arc-20160816; b=jVTD4p5Rc6URcWCCaie9QmEhRXULQ4nQGZleNrUln4MUZVyiImr1cPXjFsBbrhhm6R AyvsttCxuYcgPQx7pcAI9xDRT07N9sGQ6VizaN/fQskJ/3xK4YYMWLsAbspmP9j9fdCM O+hDqjSuXvx3LvCVAoeJHeHjIpTgRWurjo64BwulUArKPC8R8CfrWEqrZgIjV6xjDvHj p6jtPQgX+5FlvRP4p+JvTfIFOpcYuiI9fICRLO/Gk6mG6rkdUwK58dr5yJPhjnF9c5+C Sr2LbwNig0IQc9hHf9TdBMRURSvmi5RgPaz2buv1cH7YyXAGjh3nxGVJZtQAILJRv+fq Kb1w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=3XR7JayyWHHxthjYdztTSkbz9X4TU79zMhmF/LR/vQo=; fh=sJ+2/4g29YdyXkoRrFZSpsL2zxijepB7X/1rB0LDDh8=; b=U/Lx/1Viiv6bhAgp7tVQeLB57zvrB7uxpDmfqNCNQJTFtVrPBog6Zr7d1TDgh9DVos HuoFeC5kGDvr9y5gO1VA5xq5HUxlWvVXNHOfhA81Kaq7AZyf0BDR+cFyRUqsTvbJK42U UtJigLZJ1+S8xyevytiuSQ6k7FW3/CVZtwVB0EZusARDTCwdVLicVTdlIjC6Tz9UtXal zRLZSglBx5Ccy8tVKWoHY9r1kx5plA/sHmhaxsJorHKFoteeRokDcIsSCFi8D1/EwaaY t+ehLWiitik9m6d32bKdcffNEsEX1lNTmxzUKBCk26P93E/Uwm8w4a/YbnV50fc+816g izCA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CjKZCT6i; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g20-20020ac85814000000b0041811c03cc3si1948917qtg.254.2023.11.17.08.09.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 08:09:04 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=CjKZCT6i; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E96D3385C41F for ; Fri, 17 Nov 2023 14:49:12 +0000 (GMT) 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 53BFC385828F for ; Fri, 17 Nov 2023 14:48:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 53BFC385828F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 53BFC385828F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700232523; cv=none; b=OiAtFY+Fvv9z31P6QoxfSK0wm9+kOkESP/dMK3IVzeOBw8roHN/KrZt4HwfjxT1TLq7pUzHH7R92s5OV7T22V41XmkTIRwb/BJ+d5CjdvIwQ78cA/KOKqW9KA8rAK+9E/3KeQmAOfedskBiBYbm8q+XjE4fNxH00E+JvUMiIG/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700232523; c=relaxed/simple; bh=Y4riu0gV8Me1y//et2ZltubtJDtu4KhVFU5QsGSMiX4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=d0JN7lDW0KfsZvDxRH00OluoFkY6mTjVtKg7snkKnZRO0V3d8c0WharR4NLKSgM97bIHEo/iCWaxx7qkMx94Rzw3kRvEkqkwvf/ZG7v5fzS78ZVCfWstzlvo0Ux400HgA1Eof0933rpItMlPJvvpnWXb3NWAb2e9CxgOMAgQMdc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700232522; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3XR7JayyWHHxthjYdztTSkbz9X4TU79zMhmF/LR/vQo=; b=CjKZCT6i3iXUDnfx1i0N7QmPu0l5OhN0qFh79cQMnpYtdmyvYEVu4rVKBckLbUAsVPLNXd MaWgRAhO/8l4SOk5eiKtE8dLdZSyZ2XhUbkz6txva9vgnnUpBLft2RyILUV+pMhFSmk4Sa K6zCb0h1II2X/1dQbbmxGxviXeHTRak= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638--A6wMlBfN22GP1vLKfHGJw-1; Fri, 17 Nov 2023 09:48:39 -0500 X-MC-Unique: -A6wMlBfN22GP1vLKfHGJw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 63B761C07553; Fri, 17 Nov 2023 14:48:39 +0000 (UTC) Received: from localhost (unknown [10.42.28.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DD115028; Fri, 17 Nov 2023 14:48:39 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add more Doxygen comments and another test for std::out_ptr Date: Fri, 17 Nov 2023 14:48:19 +0000 Message-ID: <20231117144838.1478158-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.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_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK autolearn=ham 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782828074354931994 X-GMAIL-MSGID: 1782828074354931994 Tested x86_64-linux. Pushed to trunk. -- >8 -- Improve Doxygen comments for std::out_ptr etc. and add a test for the feature test macro. Also remove a redundant preprocessor condition. Ideally the docs for std::out_ptr and std::inout_ptr would show examples of how to use them and what they do, but that would take some effort. I'll aim to do that before GCC 14 is released. libstdc++-v3/ChangeLog: * include/bits/out_ptr.h: Add Doxygen comments. Remove a redundant preprocessor condition. * testsuite/20_util/smartptr.adapt/version.cc: New test. --- libstdc++-v3/include/bits/out_ptr.h | 41 ++++++++++++++++--- .../20_util/smartptr.adapt/version.cc | 19 +++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/smartptr.adapt/version.cc diff --git a/libstdc++-v3/include/bits/out_ptr.h b/libstdc++-v3/include/bits/out_ptr.h index 49712fa7e31..aeeb6640441 100644 --- a/libstdc++-v3/include/bits/out_ptr.h +++ b/libstdc++-v3/include/bits/out_ptr.h @@ -43,8 +43,14 @@ namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION -#ifdef __glibcxx_out_ptr // C++ >= 23 - /// Adapt a smart pointer for functions taking an output pointer parameter. + /// Smart pointer adaptor for functions taking an output pointer parameter. + /** + * @tparam _Smart The type of pointer to adapt. + * @tparam _Pointer The type of pointer to convert to. + * @tparam _Args... Argument types used when resetting the smart pointer. + * @since C++23 + * @headerfile + */ template class out_ptr_t { @@ -276,7 +282,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template friend class inout_ptr_t; }; - /// Adapt a smart pointer for functions taking an output pointer parameter. + /// Smart pointer adaptor for functions taking an inout pointer parameter. + /** + * @tparam _Smart The type of pointer to adapt. + * @tparam _Pointer The type of pointer to convert to. + * @tparam _Args... Argument types used when resetting the smart pointer. + * @since C++23 + * @headerfile + */ template class inout_ptr_t { @@ -367,6 +380,15 @@ namespace __detail } /// @endcond + /// Adapt a smart pointer for functions taking an output pointer parameter. + /** + * @tparam _Pointer The type of pointer to convert to. + * @param __s The pointer that should take ownership of the result. + * @param __args... Arguments to use when resetting the smart pointer. + * @return A std::inout_ptr_t referring to `__s`. + * @since C++23 + * @headerfile + */ template inline auto out_ptr(_Smart& __s, _Args&&... __args) @@ -379,6 +401,15 @@ namespace __detail return _Ret(__s, std::forward<_Args>(__args)...); } + /// Adapt a smart pointer for functions taking an inout pointer parameter. + /** + * @tparam _Pointer The type of pointer to convert to. + * @param __s The pointer that should take ownership of the result. + * @param __args... Arguments to use when resetting the smart pointer. + * @return A std::inout_ptr_t referring to `__s`. + * @since C++23 + * @headerfile + */ template inline auto inout_ptr(_Smart& __s, _Args&&... __args) @@ -391,6 +422,7 @@ namespace __detail return _Ret(__s, std::forward<_Args>(__args)...); } + /// @cond undocumented template template inline @@ -422,11 +454,10 @@ namespace __detail else __reset(); } -#endif // __glibcxx_out_ptr + /// @endcond _GLIBCXX_END_NAMESPACE_VERSION } // namespace #endif // __glibcxx_out_ptr #endif /* _GLIBCXX_OUT_PTR_H */ - diff --git a/libstdc++-v3/testsuite/20_util/smartptr.adapt/version.cc b/libstdc++-v3/testsuite/20_util/smartptr.adapt/version.cc new file mode 100644 index 00000000000..5110f8b371e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/smartptr.adapt/version.cc @@ -0,0 +1,19 @@ +// { dg-do preprocess { target c++23 } } +// { dg-add-options no_pch } + +#include + +#ifndef __cpp_lib_out_ptr +# error "Feature test macro for out_ptr is missing in " +#elif __cpp_lib_out_ptr < 202106L +# error "Feature test macro for out_ptr has wrong value in " +#endif + +#undef __cpp_lib_out_ptr +#include + +#ifndef __cpp_lib_out_ptr +# error "Feature test macro for out_ptr is missing in " +#elif __cpp_lib_out_ptr < 202106L +# error "Feature test macro for out_ptr has wrong value in " +#endif