-
Notifications
You must be signed in to change notification settings - Fork 767
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
Another shared_from_this bug... This time, invalidated shared_from_this state after SAVING (not loading) #68
Comments
I am at work right now, so I cannot do further testing for a few hours, but I have a hunch it might be related to cereal::base_class. When I get home I plan on removing the cereal::base_class call and seeing if it still breaks. |
Much simpler test case: struct A : std::enable_shared_from_this<A>
{
template <class Archive>
void serialize( Archive & ar )
{ }
virtual void foo() = 0;
};
struct B : A
{
template <class Archive>
void serialize( Archive & ar )
{ }
void foo() {}
};
CEREAL_REGISTER_TYPE(B);
int main()
{
{
cereal::JSONOutputArchive ar(std::cout);
std::shared_ptr<A> a( new B() );
ar( a );
auto x = a->shared_from_this();
}
} |
Fairly confident the error is due to this line. In this function we are being given a void pointer to whatever your Also this has nothing to do with |
Awesome, thanks for looking into it! Yeah, my test case was quite heavy in comparison to the true minimal example you provided. I was just so relieved to have it nailed down to something outside of my own code base. Also glad to help with another report! :) |
cereal no longer permanently modifies the state of internal workings of std::enable_shared_from_this when saving. cereal *should* be completely compatible with both saving and loading anything that inherits from this now. This fixes issue #68 - note that there is still a minor issue regarding classes declared final that will run into a bug with the way we check for enable_shared_from_this (see issue #65). Issue #65 will be addressed in the future by changing the way we check for derivation from enable_shared_from_this. In the current scheme, we can detect this even if you use protected inheritance. In the future, cereal will not be able to get around protected inheritance of enable_shared_from without befriending cereal::access. This will come at the benefit of allowing classes declared final to be used with polymorphic serialization.
Apparently MSVC doesn't want typename where it makes sense to use typename (dependent type from a template). Preprocessor verbosely saves the day, yet again. Relates #68
Hoping this is the last of the issues related to |
Agreed. Love you. Want your babies. Thank god. I'll post again if I find any more bugs. My code base seems to be very useful for picking out this kind of intricate bullshit. :S |
This bug literally took me a month to write a minimal test case for. I assumed I was doing something bad, but it seems cereal's archive molests the shared_from_this state without calling a destructor!
See the line with: //BUSTED
The text was updated successfully, but these errors were encountered: