re: #34032 (review)
@ryanofsky No rush, but if you get a chance to take another look here before branch-off [1], that’d be great. I think the pull is currently blocked because of your use of the spicy word “unsafe” 😅
I’m not saying the pull is unsafe. I’m saying this specific commit fa90c4434176860eb01c8197fda226f6e7bb1f70 is unsafe and the updated commit message is misleading.
This commit is unsafe and the new commit message saying that pointer operators throwing exceptions is “fine” is misleading, because if these operators throw exceptions, code can catch those exceptions, and that code will be broken when Expected is replaced with expected, in bad ways triggering UB, in code paths likely to be missing test coverage because we often don’t have tests checking error paths.
However, the pull request as a whole is safe because a later commit fa15f71e34e53ecaa32c4b4f2102feed7601c62c adds noexcept. That later commit fixes safety issue apparently by accident because it does not even mention any change in behavior.
IMO, this pull is not in a good state even if it is technically safe. These issues could be fixed at a surface level by adding noexcept in fa90c4434176860eb01c8197fda226f6e7bb1f70 instead of fa15f71e34e53ecaa32c4b4f2102feed7601c62c. In that case, it would be good to have comments next to these noexcepts, because normally when developers see noexcept we think “exceptions are not expected to be thrown here” not “exceptions are thrown one level down from here but this triggers std::terminate and that is good.”
I do think the real mistake here is implementing pointer methods in terms of value() instead of the other way around. Using value() complicates implementation of this class, makes error reporting more confusing and less reliable, and sets a bad example of how you should deal with nullable values in c++. Using value instead of bool/*/-> makes unsafe dereferences look like normal method calls, and negates decades of pattern recognition c/c++ developers have dealing with code with nullable values.