gcc/libstdc++-v3/testsuite/20_util/move_only_function
Tomasz Kamiński 45ea1c542e libstdc++: Reduce chances of object aliasing for function wrapper.
Previously, an empty functor (EmptyIdFunc) stored inside a
std::move_only_function being first member of a Composite class could have the
same address as the base of the EmptyIdFunc type (see included test cases),
resulting in two objects of the same type at the same address.

This commit addresses the issue by moving the internal buffer from the start
of the wrapper object to a position after the manager function pointer. This
minimizes aliasing with the stored buffer but doesn't completely eliminate it,
especially when multiple empty base objects are involved (PR121180).

To facilitate this member reordering, the private section of _Mo_base was
eliminated, and the corresponding _M_manager and _M_destroy members were made
protected. They remain inaccessible to users, as user-facing wrappers derive
from _Mo_base privately.

libstdc++-v3/ChangeLog:

	* include/bits/funcwrap.h (__polyfunc::_Mo_base): Reorder _M_manage
	and _M_storage members. Make _M_destroy protected and remove friend
	declaration.
	* testsuite/20_util/copyable_function/call.cc: Add test for aliasing
	base class.
	* testsuite/20_util/move_only_function/call.cc: Likewise.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-08-27 06:35:04 +02:00
..
call.cc libstdc++: Reduce chances of object aliasing for function wrapper. 2025-08-27 06:35:04 +02:00
cons.cc
conv.cc libstdc++: Pass small trivial types by value in polymorphic wrappers 2025-06-02 13:52:35 +02:00
incomplete_neg.cc libstdc++: Pass small trivial types by value in polymorphic wrappers 2025-06-02 13:52:35 +02:00
move.cc libstdc++: Avoid double indirection in move_only_function when possible [PR119125] 2025-05-14 13:34:01 +02:00
version.cc