Re:The Year of C++ Successor Languages
by mgaunard on Monday January 02, 2023 @08:35AM
(#34217655)
A variant does not make that guarantee, it just segregates it.
[ Parent
| on HN ]
Same for exceptions really. Exceptions don't give any guarantee of non-erroneous state. The guarantees that you're talking about actually come from how construction and deconstruction work in C++ (note how it plays with early returns just fine, no exceptions needed). And these construction semantics can be implemented with variant types as well, it's completely unrelated.
The prevent the control flow from continuing in that direction, which prevents those variables from ever existing.
Early return is nothing like exceptions. Early returns needs to return something which passes the problem to someone else. It's also a choice to do it at all.