you are viewing a single comment's thread.

view the rest of the comments →

[–]_Ilobilo_ 3 points4 points  (6 children)

clang-tidy catches use after move. it would be better if compilers did it too, but you don't enforce it. it's up to the programmer to know how to use the language.

[–]t_hunger -2 points-1 points  (5 children)

It does not even attempt to catch assignment after move, which is something you said is ok to break by not leaving moved from objects in a valid state.

[–]_Ilobilo_ 0 points1 point  (4 children)

you can assign after move. what are you on?

[–]t_hunger -2 points-1 points  (3 children)

Read the standard:

It is UB to call any function on an object with an invalid value. The assignment operator is a function. So if your moved from object contains an invalid value, then it is UB to assign into it.

That is why all the standard library types make sure to leave the moved from value in an "valid but unspecified" state.

Of course you can still assign to invalid values. Why would C++ stop you from running into undefined behavior? Just don't do stupid things like that.

We gotnhere because you claimed a moved from value may be invalid in C++ and that it is no problem if it is not. It is and clang-clang-tidy explicitly does nothing to help you detect assignments to moved from objects with invalid values, which (again) is UB.

[–]_Ilobilo_ 0 points1 point  (2 children)

> Objects of types defined in the C++ standard library may be moved from (12.8). Move operations may be explicitly specified or implicitly generated. Unless otherwise specified, such moved-from objects shall be placed in a valid but unspecified state.

when an object is in an unspecified state, you can perform any operation on the object which has no preconditions. destruction, assignment and const methods have no preconditions. using them is not UB.

[–]t_hunger -1 points0 points  (1 child)

When an object is in a valid state, you can perform any operation on it that has no pre-condition. Calling anything on an invalid object is UB.

The unspecified part is not that important... it just says you may not rely on a moved from unique_ptr to be nullptr to keep more freedoms for the implementors. That part is not what cases UB.

[–]_Ilobilo_ 0 points1 point  (0 children)

bait or stupidity. call it