]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Reduce size of std::bind_front(empty_type) result [PR108290]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 5 Jan 2023 11:35:35 +0000 (11:35 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 5 Jan 2023 16:28:43 +0000 (16:28 +0000)
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
libstdc++-v3/testsuite/20_util/function_objects/bind_front/107784.cc

index dddd22fcd043163bfe5ea60bb9d47f630fa4fbf2..5dff5be089d4cbbd1d6a5b6c6acb7122d3e2364b 100644 (file)
@@ -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<typename _Fn, typename... _Args>
index ec255f3ee363a6133fe5e99fb63a7136671dd403..f1f8cee45094928b10eb798c34a55c0a950725ef 100644 (file)
@@ -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<typename T> 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));