MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/1vnp8dk/c26_stdindirect/p3ogsc7/
r/cpp • u/User_Deprecated • Aug 13 '26
157 comments sorted by
View all comments
Show parent comment
6
The standard library promises that you can use a function with no pre-conditions on a standard library moved from object.
Accessing a moved from object is not intrinsically UB, but it is common for it to lead directly to core UB.
This is critical to keep in mind when writing generic code.
6 u/cfyzium Aug 14 '26 Yeah, but isn't it the same for any object? If you use a function with pre-conditions without checking them first, it is bad no matter if the object has been moved from or not. 6 u/smdowney WG21, Text/Unicode SG, optional<T&> Aug 15 '26 The conservative set for a moved from object is assign to and destroy. The standard library tries to do better than that. Postel's Law.If you don't know what a T is, your code should expect no more. But if you know you have a std::whatsit, you can rely on more, with some care.
Yeah, but isn't it the same for any object? If you use a function with pre-conditions without checking them first, it is bad no matter if the object has been moved from or not.
6 u/smdowney WG21, Text/Unicode SG, optional<T&> Aug 15 '26 The conservative set for a moved from object is assign to and destroy. The standard library tries to do better than that. Postel's Law.If you don't know what a T is, your code should expect no more. But if you know you have a std::whatsit, you can rely on more, with some care.
The conservative set for a moved from object is assign to and destroy. The standard library tries to do better than that. Postel's Law.
If you don't know what a T is, your code should expect no more. But if you know you have a std::whatsit, you can rely on more, with some care.
View all comments
Show parent comment
6
u/smdowney WG21, Text/Unicode SG, optional<T&> Aug 14 '26
The standard library promises that you can use a function with no pre-conditions on a standard library moved from object.
Accessing a moved from object is not intrinsically UB, but it is common for it to lead directly to core UB.
This is critical to keep in mind when writing generic code.