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

Corrected invocation of boost::promise<T>::set_exception #536

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

karzhenkov
Copy link

Closes #534

@sewenew
Copy link
Owner

sewenew commented Dec 10, 2023

Sorry, but I don't think this is a good solution. boost::promise's destructor is not virtual, so deriving from it might cause some problem.

Maybe we should replace all Promise::set_exception with a set_exception(Promise &pro, exception_ptr err) function. With boost enabled, we can make a specialized set_exception to handle these stuffs.

// For std::promise
void set_exception(Promise &pro, exception_ptr err) {
    pro.set_exception(err);
}
// For boost::promise
void set_exception(Promise &pro, exception_ptr err) {
    try {
        rethrow_exception(err);
    } catch (...) {
       pro.set_exception(boost::current_exception());
    }
}

I'll do some tests on this solution later.

@karzhenkov
Copy link
Author

karzhenkov commented Dec 11, 2023

The only potential problem with non-virtual destructor is destruction through a pointer to a base class. Since pointers to the base (boost::promise<T>) are not used in the code directly, this cannot happen.

To detect the problem at compile time, CppCoreGuidlines recommend to make the constructor of the base protected. Obviously, we cannot follow this recommendation here. However, such check is not mandatory and is actually not needed in this case.

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

Successfully merging this pull request may close these issues.

[BUG] Incorrect exception type when using Boost futures
2 participants