Repository navigation
fix: bad_expected_access::what() returns the error message - #1269
Conversation
…ree#1263) what() returned a fixed "bad_expected_access", so the actual error of a failed Expected<T> was lost. When the error type converts to std::string, the message is now returned instead. It is stored in a shared_ptr so that copying the exception does not allocate.
…nd copy Return m_error.c_str() through an overload on std::string, with a generic fallback for other error types. No extra member, so the class layout is unchanged, and copying the exception no longer copies the message twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @azerbenali, this is a real usability win: I pushed one commit (dcea354) on top of a merge of master that simplifies it. |
|
Thanks Davide! Appreciate the improvements and your help! |
Fixes #1263
what()now returns the error when it converts tostd::string, otherwise the old message. Kept C++11-compatible (tag dispatch instead ofif constexpr) since the header targets C++11, and the message is in ashared_ptrso copying the exception doesn't allocate.Note: with C++23
nonstd::expectedmaps tostd::expected, which this doesn't change.