3 ms·
It changed, it used to be immediately considered UB, but isn’t any longer, as your grandparent says, that’s what is documented now. It still leads to UB, but is
by steveklabnik 3y ago
It changed, it used to be immediately considered UB, but isn’t any longer, as your grandparent says, that’s what is documented now. It still leads to UB, but isn’t inherently UB on its own. There’s a term for this but I’m forgetting at the moment and search is failing me.
I agree that bstr is what you want unless you specifically understand this detail and know why it is the way it is.
- afdbcreid 3y agoThe term is "library UB" versus "language UB". To be clear, you should still avoid it most of the times.
- steveklabnik 3y agoAh yes, thank you.
- _nalply 3y agoWould you say library undefined behavior is just a violation of a library invariant? Like `&str` and `String` containing valid UTF-8? I admit that a library invariant is allowed to be violated temporarily under some strict preconditions. One example are bank account money transfers, where the credit and debit don't happen exactly simultaneously. Something similar could happen in a library. But for language UB this doesn't work. Why? Is it because of compile-time optimizations possibly deleting code restoring the invariant?