You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Base
{
};
class Derived : public Base
{
};
class SomeOtherClass
{
Derived* mPointerProperty;
};
SomeOtherClass* object = new SomeOtherClass();
object->mPointerProperty = nullptr;
variant value = object->get_type().get_property("mPointerProperty").get_value(object);
Now, suppose we want to retrieve the pointer value from the variant and store it in a base pointer. We can do two things:
Base* pointer_value = value.get_value<Base*>(); // Works because Derived is derived from Base
This works because Derived is derived from Base. Or we can do:
This doesn't work; garbage is returned and converted_ok remains false, which is unexpected. The reason for this appears to be that variant::convert does not correctly deal with inheritance hierarchies when the value is a nullptr; when faced with this case, it goes through variant::try_pointer_conversion, which calls type::apply_offset, which returns a nullptr (because ptr is null), causing the function to fail.
I'm not sure how to fix it this time :)
The text was updated successfully, but these errors were encountered:
Thanks for reporting this issue. It is fixable.
Actually, the function type::apply_offset needs to be adjusted, or I add a new one.
if (src_raw_type == tgt_raw_type || ptr == nullptr)
return ptr;
The nullptr check needs to be removed and the registered conversion function (class_list.m_conversion_list[i](info.m_ptr);) needs be called, if the type is in the inheritance graph.
We cannot do a simply reinterpret_cast. The conversion functions contains the static_casts to the pointer types. Thats what we need to call.
Its not that much code, I need to see when I have time for this. At moment I working on issue 57
Consider the following code:
Now, suppose we want to retrieve the pointer value from the variant and store it in a base pointer. We can do two things:
This works because Derived is derived from Base. Or we can do:
This doesn't work; garbage is returned and converted_ok remains false, which is unexpected. The reason for this appears to be that
variant::convert
does not correctly deal with inheritance hierarchies when the value is a nullptr; when faced with this case, it goes throughvariant::try_pointer_conversion
, which callstype::apply_offset
, which returns a nullptr (becauseptr
is null), causing the function to fail.I'm not sure how to fix it this time :)
The text was updated successfully, but these errors were encountered: