public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-8910] libstdc++: Fix std::move_only_function for incomplete parameter types Date: Mon, 14 Nov 2022 18:34:54 +0000 (GMT) [thread overview] Message-ID: <20221114183454.5589A3887F77@sourceware.org> (raw) https://gcc.gnu.org/g:9c45321cdbf48419ced5d7d442e2f033ab8f476e commit r12-8910-g9c45321cdbf48419ced5d7d442e2f033ab8f476e Author: Jonathan Wakely <jwakely@redhat.com> 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<typename _Tp> - using __param_t - = __conditional_t<is_trivially_copyable_v<_Tp> - && sizeof(_Tp) <= sizeof(long), - _Tp, _Tp&&>; + using __param_t = __conditional_t<is_scalar_v<_Tp>, _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 9ca0a60a24e..0c7f58d77a0 100644 --- a/libstdc++-v3/testsuite/20_util/move_only_function/call.cc +++ b/libstdc++-v3/testsuite/20_util/move_only_function/call.cc @@ -190,10 +190,21 @@ test04() VERIFY( std::move(std::as_const(f5))() == 3 ); } +struct Incomplete; + +void +test_params() +{ + std::move_only_function<void(Incomplete)> f1; + std::move_only_function<void(Incomplete&)> f2; + std::move_only_function<void(Incomplete&&)> f3; +} + int main() { test01(); test02(); test03(); test04(); + test_params(); }
reply other threads:[~2022-11-14 18:34 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221114183454.5589A3887F77@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).