-
Notifications
You must be signed in to change notification settings - Fork 435
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
Variant::convert does not function correctly with null pointers if types don't match exactly #59
Comments
Thanks for reporting this issue. It is fixable.
The |
…types I.e. with nullptr's only a downcast is possible, not an upcast. Fiexe #59
I added a fix, please check whether its working for you or not. |
Thanks! |
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: