You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am not a language lawyer, but I think it would be nice if mut was documented in a sense that if it is technically UB(as used in examples in tutorial), but it works in practice then that is is mentioned (in docs or code comments).
cppref says this:
const_cast makes it possible to form a reference or pointer to non-const type that is actually referring to a const object or a reference or pointer to non-volatile type that is actually referring to a volatile object. Modifying a const object through a non-const access path and referring to a volatile object through a non-volatile glvalue results in undefined behavior.
Apologies in advance if I misunderstood the cppref quote.
The text was updated successfully, but these errors were encountered:
It isn't UB as used in the examples. That said, mut is much too powerful. I would stick to specifying the lambda as mutable if all you need is to modify a lambda's capture for a test (as opposed to non-testing uses, as mutable affects all captures, which might have unintended consequences. See https://wg21.link/P2034).
Apologies, this is all very weird to me, but you are right, I always assumed that writing to any const object is UB, unless it was a const ref to something that was originally mutable.
I am not a language lawyer, but I think it would be nice if mut was documented in a sense that if it is technically UB(as used in examples in tutorial), but it works in practice then that is is mentioned (in docs or code comments).
cppref says this:
Apologies in advance if I misunderstood the cppref quote.
The text was updated successfully, but these errors were encountered: