Skip to content

adobe::poly and SOO question #95

@NelsonEloi

Description

@NelsonEloi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions