From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 2AC2B3854177; Fri, 21 Oct 2022 09:51:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2AC2B3854177 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666345864; bh=1AOXCH/+iUaLM9oTVWvjtiFLevVazLa3pNPmqzDXzb0=; h=From:To:Subject:Date:From; b=UzrxoJVG/p9vUf5t2cguOXUmJQC0BRMZ9wpQOsuOuUZj21jTL3zxZtDn4nE1x98zs 4/oUfF1VIH5nDZ/ZPzIMLwsfOtpjO1PaQJ8bRVtVx/cFjXSufsGZBvpWVdQm5WP6OP jeCvVymr30x3WLbfcg9Q5X824pPl0+jTlkKb3n8c= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-3435] libstdc++: Fix std::move_only_function for incomplete parameter types X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: a9de836c2b22f878cff592b96e11c1b95d4d36ee X-Git-Newrev: 33de0ffcf050e581eb931eb4f1c5ad9c0cdc6bf6 Message-Id: <20221021095104.2AC2B3854177@sourceware.org> Date: Fri, 21 Oct 2022 09:51:04 +0000 (GMT) List-Id: https://gcc.gnu.org/g:33de0ffcf050e581eb931eb4f1c5ad9c0cdc6bf6 commit r13-3435-g33de0ffcf050e581eb931eb4f1c5ad9c0cdc6bf6 Author: Jonathan Wakely Date: Tue Oct 18 20:49:42 2022 +0100 libstdc++: Fix std::move_only_function for incomplete parameter types 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. Diff: --- libstdc++-v3/include/bits/mofunc_impl.h | 5 +---- libstdc++-v3/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(); }