Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

future: avoid inheriting from future payload type #2598

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

avikivity
Copy link
Member

The uninitialized_wrapper_base will, when possible inherit from the future payload type T in order to apply the empty base optimization (if sizeof(T) == 0). However, this injects methods from T into the scope of uninitialized_wrapper and classes that inherit from it, such as future_state. If one of the names of the methods in future_state clashes with a member of T, we get a compilation failure.

Fix by avoiding the inheritance branch of uninitialized_wrapper_base and using the composition branch, and use [[no_unique_address]] to avoid bloating future<some_empty_class>.

It turns out that we delete the specialization that was used with internal::monostate (corresponding to future<>), and so we have to specialize uninitialized_wrapper for it.

I verified that sizeof(future<>) isn't changed by the patch.

The uninitialized_wrapper_base will, when possible inherit from
the future payload type T in order to apply the empty base
optimization (if sizeof(T) == 0). However, this injects methods
from T into the scope of uninitialized_wrapper and classes
that inherit from it, such as future_state. If one of the names
of the methods in future_state clashes with a member of T, we
get a compilation failure.

Fix by avoiding the inheritance branch of uninitialized_wrapper_base
and using the composition branch, and use [[no_unique_address]]
to avoid bloating future<some_empty_class>.

It turns out that we delete the specialization that was used
with internal::monostate (corresponding to future<>), and so
we have to specialize uninitialized_wrapper for it.

I verified that sizeof(future<>) isn't changed by the patch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant