From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Type: text/plain Content-Transfer-Encoding: 8bit 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 List-Id: 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); +} -- 2.43.0