From patchwork Fri Oct 21 09:51:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 6607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp595371wrr; Fri, 21 Oct 2022 02:52:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7UH5YwAI89CLFqu3Ou3WNos4ouFTnIrG0RphYS5J7VRH3WK0rx4cb9BqCwZQuJ3SsPi8NG X-Received: by 2002:a17:907:808:b0:730:54cc:b597 with SMTP id wv8-20020a170907080800b0073054ccb597mr14659147ejb.434.1666345964927; Fri, 21 Oct 2022 02:52:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666345964; cv=none; d=google.com; s=arc-20160816; b=ECsQDpGpMxFdMOUXIl3K+khA3JOBnYoUS1TykcOipw6buAq0xdYyxFaCtBncpxpddL 4wSm8mIMcjxP9owJvHSUVpzNS2HL+sHS59wOZq7ETZvq3YLqwhAz2xuhn01SntE91Z5I Yku8mHMrWqircv4X6cEb0kPsmL799kHuZhrYU6VRRWl4Dij2jqMMmBO5frpZsCWiJ248 Elwrl0uIEx+QoZRQEvcN0PU4UULiyvcG8KJQp4mpCeg7+qoY37t7+xp0CWPz4sUXxPgL XZMrw2GFFRr8t24VpKXwgiVhOYAq7FmGmYOAxm7OMrjyUsiYaO8oZoBltyjyiy97+eY8 cAxg== 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=PtE6OJKPHd7oEtvG2SOalXDgfXlfokGxX3c5WfHGx8Q=; b=o67/8oxS6jUKItjzSqvpil+Waxo/99oZ3bFUJ5BuTi8zMsyZAsLjdsWCzOA+wH4YaX 1tPW0NKiJ7LqQi9c0K0R7SlBZ9hlsk3cVgwdJndX7uoC1MSIPmX7YXa3aVwEplJZ2zsS ref9X2vfsoA2G7rLdtnpvQvB7CKPstpOtYcHThSNwA5aEWZQytcLhj1zfKMEXxMXK9w3 dInH7E1pvFsi0Bw9OBfFv2VmCWOPYXjSqdHCL9qzhsnAYcWvK7Cj6Z0AcEwAtsepDyGD U+nUY/wKF9W6yjz99ewdrCQODJxlewLcBftnIkWl2RT/3+13fsFMmjHBryb7Ol+JG2dX pw3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UjHXfzW4; 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 q19-20020a056402519300b00450e1ffe3edsi20917263edd.382.2022.10.21.02.52.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 02:52:44 -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=UjHXfzW4; 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 2B88738515DF for ; Fri, 21 Oct 2022 09:52:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B88738515DF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666345927; bh=PtE6OJKPHd7oEtvG2SOalXDgfXlfokGxX3c5WfHGx8Q=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=UjHXfzW47amn28ohUR/lxm0VMiCR5hUnMWPdQ4+KosLEhGhGTR22e0xJdxO7RrLWe o6yuqydsPu8nFlAqwBCpQo4q7Wv/TWVGxAIBn6vfkzvESD4MvFStyEuV+CQ+gbhDd2 9f3sev8x2BIkfp0tYuzobtgWVvMd630ej9fv8UtU= 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 CA50D385E037 for ; Fri, 21 Oct 2022 09:51:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CA50D385E037 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-675-4NQcP9nSMEyKHBuILy400w-1; Fri, 21 Oct 2022 05:51:21 -0400 X-MC-Unique: 4NQcP9nSMEyKHBuILy400w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EAD513814586; Fri, 21 Oct 2022 09:51:20 +0000 (UTC) Received: from localhost (unknown [10.33.36.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id B37772024CBB; Fri, 21 Oct 2022 09:51:20 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix std::move_only_function for incomplete parameter types Date: Fri, 21 Oct 2022 10:51:19 +0100 Message-Id: <20221021095119.473425-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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.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?1747290386431199975?= X-GMAIL-MSGID: =?utf-8?q?1747290386431199975?= Tested powerpc64le-linux. Pushed to trunk. -- >8 -- The std::move_only_function::__param_t alias template attempts to optimize argument passing for the invoker, by passing by rvalue reference for types that are non-trivial or large. However, the precondition for is_trivally_copyable makes it unsuitable for using here, and can cause ODR violations. Just use is_scalar instead, and pass all class types (even small, trivial ones) by value. libstdc++-v3/ChangeLog: * include/bits/mofunc_impl.h (move_only_function::__param_t): Use __is_scalar instead of is_trivially_copyable. * testsuite/20_util/move_only_function/call.cc: Check parameters involving incomplete types. --- libstdc++-v3/include/bits/mofunc_impl.h | 5 +---- .../testsuite/20_util/move_only_function/call.cc | 11 +++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/bits/mofunc_impl.h b/libstdc++-v3/include/bits/mofunc_impl.h index 405c4054642..47e1e506306 100644 --- a/libstdc++-v3/include/bits/mofunc_impl.h +++ b/libstdc++-v3/include/bits/mofunc_impl.h @@ -205,10 +205,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION private: template - using __param_t - = __conditional_t - && sizeof(_Tp) <= sizeof(long), - _Tp, _Tp&&>; + using __param_t = __conditional_t, _Tp, _Tp&&>; using _Invoker = _Res (*)(_Mofunc_base _GLIBCXX_MOF_CV*, __param_t<_ArgTypes>...) noexcept(_Noex); diff --git a/libstdc++-v3/testsuite/20_util/move_only_function/call.cc b/libstdc++-v3/testsuite/20_util/move_only_function/call.cc index 68aa20568eb..3e159836412 100644 --- a/libstdc++-v3/testsuite/20_util/move_only_function/call.cc +++ b/libstdc++-v3/testsuite/20_util/move_only_function/call.cc @@ -191,10 +191,21 @@ test04() VERIFY( std::move(std::as_const(f5))() == 3 ); } +struct Incomplete; + +void +test_params() +{ + std::move_only_function f1; + std::move_only_function f2; + std::move_only_function f3; +} + int main() { test01(); test02(); test03(); test04(); + test_params(); }