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.129.124]) by sourceware.org (Postfix) with ESMTPS id CECB3385382D for ; Fri, 21 Oct 2022 09:51:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CECB3385382D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666345884; 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=PtE6OJKPHd7oEtvG2SOalXDgfXlfokGxX3c5WfHGx8Q=; b=WEqKl6WzPVGZBP0X4swBwry3tzE/x9s5uFwS8huvZcedFXkS9diftdYRvjdXHiWJLcUmJa P6ov9XQIZO9WdHnd4MKvRCkwSsgNMO6FZitbE4Kv3u+UjN6IJu0+MIBdFzHjUvh0IWlp5o pBly9Q6NkTGRadJLwLSiEIQeJYZrMx0= 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) From: Jonathan Wakely 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 Content-Type: text/plain Content-Transfer-Encoding: 8bit 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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(); } -- 2.37.3