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.133.124]) by sourceware.org (Postfix) with ESMTPS id 6FC283858C60 for ; Thu, 5 Jan 2023 16:29:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6FC283858C60 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=1672936165; 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=paM9qNTspn99q7sGWoLY5km/SG+iBQPeCJM+WlMN+UQ=; b=KzEwyMcwOqpYb+Qk18N0SqZLYC63MmxhB06+6gt1Y1UHENXxeYfKb/g9Q4e/UF5Xj+hSpK b3yF+oWFLSdfQkq+/GTu92OlpKbX64tPjKqbcWXOZGwN5RBII7vH1dIDb+DsdqOsOdx294 FDZhy9WVO4FBRdi4OT10ufdn3j5rnEM= 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-336-c2x_y4eyPqmocZS70fk4_w-1; Thu, 05 Jan 2023 11:29:14 -0500 X-MC-Unique: c2x_y4eyPqmocZS70fk4_w-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5E9B729AA3BE; Thu, 5 Jan 2023 16:29:14 +0000 (UTC) Received: from localhost (unknown [10.33.36.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CDC41121314; Thu, 5 Jan 2023 16:29:13 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] =?UTF-8?q?libstdc++:=C2=A0Reduce=C2=A0size=C2=A0of?= =?UTF-8?q?=C2=A0std::bind=5Ffront(empty=5Ftype)=C2=A0result=20[PR108290]?= Date: Thu, 5 Jan 2023 16:29:11 +0000 Message-Id: <20230105162911.82041-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.2 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,URI_HEX 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 -- 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. --- libstdc++-v3/include/std/functional | 6 +-- .../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)); -- 2.39.0