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

adobe::poly and SOO question #95

Open
NelsonEloi opened this issue Jan 12, 2023 · 1 comment
Open

adobe::poly and SOO question #95

NelsonEloi opened this issue Jan 12, 2023 · 1 comment

Comments

@NelsonEloi
Copy link

Good day all,

I was looking at adobe::poly and remember the Small Object Optimization post done by Sean Parent https://stlab.cc/tip/2017/12/23/small-object-optimizations.html

In reading the poly.hpp implementation it seem like it suffers from the same undefined behavior of casting the stored object to its base when the base was never stored.

When you do:
template
explicit poly_base(T x,
typename boost::disable_if<boost::is_base_of<poly_base, T>>::type* = 0) {
::new (storage()) implementation::poly_instance<Instance>(std::move(x));
}

You're storing a poly_instance, that will be a class derived from optimized_storage_type, derived from either poly_state_local or poly_state_remote, that finally derives from the interface.

Then when you do
interface_type& interface_ref() { return static_cast<interface_type>(storage()); }

We are just casting a typedef double storage_t[2]; to the interface class, when it was never stored there because a poly_instance was, granted the only ones that have data are poly_state_local and poly_state_remote, bu the interface is virtual and that is the first violation mention by Sean Parent

Did I missed something or understood the issue wrong, if so please ignore this and accept my apologies.

@sean-parent
Copy link
Member

You are correct. This is UB.

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

No branches or pull requests

2 participants