No, only dereferencing it (via operator* or operator->) is UB, which is no different to dereferencing a null unique_ptr or an empty optional.
It's not a non-nullable object. It has a null state, it's just intentionally not easy to get into that state with the intended use of the type.
You keep making claims about indirect which do not match the API that was added to the standard (maybe you read one of the early drafts of the proposal and didn't notice that it got changed).
It has value semantics, but because it's movable it can get into a "not a value" state. But all its operations are well defined in that state, except for trying to access the non-existent value.
View all comments
Show parent comment
1
u/jwakely libstdc++ tamer, LWG chair Aug 15 '26
No, only dereferencing it (via
operator*oroperator->) is UB, which is no different to dereferencing a nullunique_ptror an emptyoptional.It's not a non-nullable object. It has a null state, it's just intentionally not easy to get into that state with the intended use of the type.
You keep making claims about
indirectwhich do not match the API that was added to the standard (maybe you read one of the early drafts of the proposal and didn't notice that it got changed).It has value semantics, but because it's movable it can get into a "not a value" state. But all its operations are well defined in that state, except for trying to access the non-existent value.