boostorg / leaf

Lightweight Error Augmentation Framework
Boost Software License 1.0
313 stars 48 forks source link

try_capture_all assert fails on catching an exception #75

Closed DirtYiCE closed 2 months ago

DirtYiCE commented 2 months ago

The documentation for try_capture_all says "catching and capturing all exceptions and all communicated error objects in the returned leaf::result object", but instead in my case it just assert fails. Simple example:

#include <boost/leaf.hpp> 

int main() {
  boost::leaf::try_capture_all([]() { throw std::runtime_error("x"); });
}

Fails with:

a.out: /usr/include/boost/leaf/detail/optional.hpp:158: T &boost::leaf::leaf_detail::optional<boost::leaf::leaf_detail::dynamic_allocator>::value(int) & [T = boost::leaf::leaf_detail::dynamic_allocator]: Assertion `has_value(key) != 0' failed.
Aborted

If I compile with -DNDEBUG, it simply SIGSEGVs... Tried with system boost 1.85 and the leaf.hpp downloadable from here, same results: https://raw.githubusercontent.com/boostorg/leaf/gh-pages/leaf.hpp

zajo commented 2 months ago

Confirming that this is a bug.

zajo commented 2 months ago

Fix is in feature/issue_75, I will merge in develop and master as soon as GHA CI passes.

zajo commented 2 months ago

Merged in master. Thanks for reporting.