From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 7F5443858D28; Thu, 5 Jan 2023 16:28:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F5443858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672936129; bh=XGQsbBasgcEnohZjDtz4a3mLcNIreN3OJLrptppKEhU=; h=From:To:Subject:Date:From; b=HYGFAcSo+Pm8fPmYbek/FjZ6zTm+gy7TB93CQi1L/9YTR1zlYKicrLo1Uyn2tOzu/ 6/k5ZeYGWzIF5D7aSViY0TsM/BQ9v6XpqSpCMQjymtaU9QbT2pBFus9SyR5hQiswnT JkcXpxiS6DzAbaNteMtonWXmZshIHaR7ubiVIH1o= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: =?utf-8?b?W2djYyByMTMtNTAzM10gbGlic3RkYysrOsKgUmVkdWNlwqBzaXplwqBv?= =?utf-8?b?ZsKgc3RkOjpiaW5kX2Zyb250KGVtcHR5X3R5cGUpwqByZXN1bHQgW1BSMTA4Mjkw?= =?utf-8?q?=5D?= X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: efce0caf2d75dff5a83812b8da2dd3725197ac7c X-Git-Newrev: e2eab3c4edb6aa9a93f982c4554cd756000934ca Message-Id: <20230105162849.7F5443858D28@sourceware.org> Date: Thu, 5 Jan 2023 16:28:49 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e2eab3c4edb6aa9a93f982c4554cd756000934ca commit r13-5033-ge2eab3c4edb6aa9a93f982c4554cd756000934ca Author: Jonathan Wakely Date: Thu Jan 5 11:35:35 2023 +0000 libstdc++: Reduce size of std::bind_front(empty_type) result [PR108290] libstdc++-v3/ChangeLog: PR libstdc++/108290 * include/std/functional (_Bind_front): Add no_unique_address attribute to data members. * testsuite/20_util/function_objects/bind_front/107784.cc: Check size of call wrappers with empty types for targets and bound arguments. Diff: --- libstdc++-v3/include/std/functional | 6 ++-- .../20_util/function_objects/bind_front/107784.cc | 38 +++++++++++++++++++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index dddd22fcd04..5dff5be089d 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -991,8 +991,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION std::forward<_CallArgs>(__call_args)...); } - _Fd _M_fd; - std::tuple<_BoundArgs...> _M_bound_args; + [[no_unique_address]] _Fd _M_fd; + [[no_unique_address]] std::tuple<_BoundArgs...> _M_bound_args; }; // Avoid the overhead of an empty tuple<> if there are no bound args. @@ -1051,7 +1051,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } private: - _Fd _M_fd; + [[no_unique_address]] _Fd _M_fd; }; template diff --git a/libstdc++-v3/testsuite/20_util/function_objects/bind_front/107784.cc b/libstdc++-v3/testsuite/20_util/function_objects/bind_front/107784.cc index ec255f3ee36..f1f8cee4509 100644 --- a/libstdc++-v3/testsuite/20_util/function_objects/bind_front/107784.cc +++ b/libstdc++-v3/testsuite/20_util/function_objects/bind_front/107784.cc @@ -10,6 +10,42 @@ struct Foo void bar() { } -// PR libstdc++/107784 +// PR libstdc++/107784 - QOI: sizeof( bind_front( Member-Function ) ) too big static_assert( sizeof(std::bind_front(&Foo::func)) == sizeof(&Foo::func) ); static_assert( sizeof(std::bind_front(&bar)) == sizeof(&bar) ); + +// PR libstdc++/108290 - QoI: bind_front captureless lambda is too big +auto empty_lambda = [](auto, auto) { return 0; }; + +struct { + void operator()(int, int, int) { } + template void operator()(T, T) { } +} empty_class; + +static_assert(sizeof(std::bind_front(empty_lambda)) == 1); +static_assert(sizeof(std::bind_front(empty_lambda, 1)) == sizeof(int)); +static_assert(sizeof(std::bind_front(empty_lambda, empty_lambda)) == 2); +static_assert(sizeof(std::bind_front(empty_lambda, empty_class)) == 1); +static_assert(sizeof(std::bind_front(empty_lambda, 1, 2)) == 2 * sizeof(int)); +static_assert(sizeof(std::bind_front(empty_lambda, '1', empty_lambda)) == 2); +static_assert(sizeof(std::bind_front(empty_lambda, '1', empty_class)) == 1); + +static_assert(sizeof(std::bind_front(empty_class)) == 1); +static_assert(sizeof(std::bind_front(empty_class, 1)) == sizeof(int)); +static_assert(sizeof(std::bind_front(empty_class, empty_lambda)) == 1); +static_assert(sizeof(std::bind_front(empty_class, empty_class)) == 2); +static_assert(sizeof(std::bind_front(empty_class, 1, 2)) == 2 * sizeof(int)); +static_assert(sizeof(std::bind_front(empty_class, '1', empty_lambda)) == 1); +static_assert(sizeof(std::bind_front(empty_class, '1', empty_class)) == 2); + +struct derived1 : decltype(std::bind_front(empty_class)) +{ + int i; +}; +static_assert(sizeof(derived1) == sizeof(int)); + +struct derived2 : decltype(std::bind_front(empty_class, empty_lambda)) +{ + int i; +}; +static_assert(sizeof(derived2) == sizeof(int));