From patchwork Fri Feb 2 14:42:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 195880 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp474796dyc; Fri, 2 Feb 2024 06:44:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFYzC4+3WT3Dq98NDnJAIy7u6oPS9U0a3a7x3T9BdDB0MUg3RLAhPpiUYHMZlV751LTuCut X-Received: by 2002:a05:622a:1745:b0:42a:8462:29f2 with SMTP id l5-20020a05622a174500b0042a846229f2mr2202143qtk.49.1706885086630; Fri, 02 Feb 2024 06:44:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706885086; cv=pass; d=google.com; s=arc-20160816; b=QhWumOVLOYKkKlNOXUvZvy9Z8uP7KIHaiRvgKRAcX8Q+bp50hSzX3ILsRt85IvdVOS eptgQlIGD3SgBv83XUoT+Dc7gei1/eFCcmj9TgIOPPnW8AEEscFITBkov7cPHaOXST25 AqN381oH+ZP9lt6xiIjUdgJauYSuH+wy+qrXsPW8k2tj/W0/K13ZJjyngXsNmMoA6y+1 jXtZmPylxXtj7zmICGwrPspRkC9s242qleLU4XlWear/f67JeLcr0tqkYBolj+t+5mqT aaFwxlY2lyWXii6S1TaprA80KpIgkQ0+RKTskvhBHkDYMH0HdBmJexFOs8fAS+RvWaX5 xj1w== 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=JEzP5z+ouzdsS3DQagxOzNNoYXHI94WiObQI0OT2cGo=; fh=5oQx8nhWwfYfZTm/L73/m13XDJcscou2o0AMpKq2bwE=; b=Ovn7N/7aFHLo9WDq8AvazhDDbbBmJdfuwWFKZTZ7/uOVLuZUYlH/VnSQpILwUCcS2z 7INq/6r/ZrAX0KgJB7UPgQHH99zTiJHzWED99EDgqgleQ6jipN03I8YOhZPwFggE3FG0 Yd8KNoL5J1xXyVWVa+bpmXhFAfD5AClt2uH6DiGWKxz7D+7bG10gDIqjEcgAqFVYT6Yz D3lSrnWspL1CNbvzY3eljcQ9cCWwVqEngVB96vW6YSsYWlkYWu4BO4Asv3FUS5Ox0xoV rS9k0M25arpYxzJbKDBGX1yPRn6eJT353pf1yGTnSxdbZ6bcmUVmtyc8d8b337CTfayp xX4Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DG9v8p5o; 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 X-Forwarded-Encrypted: i=1; AJvYcCUsgdny695Vj/bpxFobsOvMZm/YJyWQjXTmJU5nOnAA56ToEQvrmjE+a5Pw1WWvTte70lyUJksLeB0EDqbUF7YhYUeZmw== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bp12-20020a05622a1b8c00b0042ab8e729bbsi2161260qtb.134.2024.02.02.06.44.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 06:44:46 -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=DG9v8p5o; 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 50F91385802F for ; Fri, 2 Feb 2024 14:44:46 +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 5966D3857C62 for ; Fri, 2 Feb 2024 14:43:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5966D3857C62 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 5966D3857C62 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=1706885021; cv=none; b=vOSDCLhRNlQTBnN/MHexPkMMypLHqwCBB34lpfO3AT7I7p2hZJ9+i0ZPY22Uv7GkS/mo39YTn2HLwm6JJYaPIlfnnBRhPyF79WbqTJpalSbHEYiL8ryypbFAvWrXz+ErQlRThm7Sm1lxKGKYVHuK//veQIuRHH7H7pEdrDyA7O8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706885021; c=relaxed/simple; bh=80ez9bw3f/fRctuiahFz6of/jw4P1rNkcGnC7tGh5xI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kC1OoK70tqa81tZQVtOWlcJ2gyCx1pRRRWUMCZzBswyHSCkIob3lfeSXXcwd3axR6Ya7i3iuzYRbuCsHofbltYIiASzLyW8pIb88cSY9cpWC+kQMmRZiNyBCdfcbLGGXh6KlmKww5oLu6plwTGiWwFP/+kaUrJEsqrDb38+p0zk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706885018; 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=JEzP5z+ouzdsS3DQagxOzNNoYXHI94WiObQI0OT2cGo=; b=DG9v8p5oHr6XLK7410/K9Ez631+BmMhHh8TpXd7yyf8pcfUJaD4+gJpRRnTZezMT7uDxUT RzXmf1zht7UGVqch0AxgbPCOkHVR6p5EiVq3PrlxVN+/jaok9De+Qyx3wxuTKrQl1XW8AL qZeu7fpKPSlnawq8VHkHbOaFqB0W9rU= 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-536-a0REDK9tNaCHSUZflF4KMg-1; Fri, 02 Feb 2024 09:43:36 -0500 X-MC-Unique: a0REDK9tNaCHSUZflF4KMg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 E9DD01C04B65; Fri, 2 Feb 2024 14:43:35 +0000 (UTC) Received: from localhost (unknown [10.42.28.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id B04273C2E; Fri, 2 Feb 2024 14:43:35 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Make std::function deduction guide support explicit object functions [PR113335] Date: Fri, 2 Feb 2024 14:42:57 +0000 Message-ID: <20240202144315.2293855-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.2 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_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: 1789798736640410809 X-GMAIL-MSGID: 1789798736640410809 Teted x86_64-linux. Pushed to trunk. -- >8 -- This makes the deduction guides for std::function and std::packaged_task work for explicit object member functions, i.e. "deducing this", as per LWG 3617. libstdc++-v3/ChangeLog: PR libstdc++/113335 * include/bits/std_function.h (__function_guide_helper): Add partial specialization for explicit object member functions, as per LWG 3617. * testsuite/20_util/function/cons/deduction_c++23.cc: Check explicit object member functions. * testsuite/30_threads/packaged_task/cons/deduction_c++23.cc: Likewise. --- libstdc++-v3/include/bits/std_function.h | 6 ++++ .../20_util/function/cons/deduction_c++23.cc | 35 +++++++++++++++++++ .../packaged_task/cons/deduction_c++23.cc | 35 +++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/libstdc++-v3/include/bits/std_function.h b/libstdc++-v3/include/bits/std_function.h index 9130f9d28e3..79b59466fe9 100644 --- a/libstdc++-v3/include/bits/std_function.h +++ b/libstdc++-v3/include/bits/std_function.h @@ -697,6 +697,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > { using type = _Res(_Args...); }; +#if __cpp_explicit_this_parameter >= 202110L + template + struct __function_guide_helper<_Res (*) (_Tp, _Args...) noexcept(_Nx)> + { using type = _Res(_Args...); }; +#endif + #if __cpp_static_call_operator >= 202207L && __cpp_concepts >= 202002L template struct __function_guide_static_helper diff --git a/libstdc++-v3/testsuite/20_util/function/cons/deduction_c++23.cc b/libstdc++-v3/testsuite/20_util/function/cons/deduction_c++23.cc index 132bfb8fbfe..8c70c102929 100644 --- a/libstdc++-v3/testsuite/20_util/function/cons/deduction_c++23.cc +++ b/libstdc++-v3/testsuite/20_util/function/cons/deduction_c++23.cc @@ -21,3 +21,38 @@ test_static_call_operator() std::function func2 = F2{}; check_type>(func2); } + +void +test_explicit_object_call_operator() +{ + // LWG 3617 - function/packaged_task deduction guides and deducing this + struct F { + int operator()(this const F&) { return 42; } + }; + + std::function g = F{}; + check_type>(g); + + struct F2 { + short operator()(this F2&, float&) { return 0; } + }; + + std::function g2 = F2{}; + check_type>(g2); + + struct F3 { + void operator()(this const F3, char*, long) { } + }; + + std::function g3 = F3{}; + check_type>(g3); + + struct F4 { + int i; + operator const int&() const { return i; } + const long& operator()(this int, const long& l) { return l; } + }; + + std::function g4 = F4{}; + check_type>(g4); +} diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction_c++23.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction_c++23.cc index 6a43cf945d8..307522a73f5 100644 --- a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction_c++23.cc +++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction_c++23.cc @@ -20,3 +20,38 @@ test_static_call_operator() std::packaged_task task2{ F2{} }; check_type>(task2); } + +void +test_explicit_object_call_operator() +{ + // LWG 3617 - function/packaged_task deduction guides and deducing this + struct F { + int operator()(this const F&) { return 42; } + }; + + std::packaged_task g{ F{} }; + check_type>(g); + + struct F2 { + short operator()(this F2&, float&) { return 0; } + }; + + std::packaged_task g2{ F2{} }; + check_type>(g2); + + struct F3 { + void operator()(this const F3, char*, long) { } + }; + + std::packaged_task g3{ F3{} }; + check_type>(g3); + + struct F4 { + int i; + operator const int&() const { return i; } + const long& operator()(this int, const long& l) { return l; } + }; + + std::packaged_task g4{ F4{} }; + check_type>(g4); +}