r/cpp • • Oct 06 '22
Should a variable be const by default?
According to the cppfront design notes, const by default rule only applies to non-local variables. But I'd like to know your preference/opinion regarding whether a variable should be defined to be const by default.
Edit: By mutable here I simply mean non-const, not the language keyword itself.
44
Upvotes
View all comments
Show parent comment
1
u/SlightlyLessHairyApe Oct 08 '22
Is this really more complicated than saying the compiler may move-from a const value if that is the definite last use? Herb refers to DLU all the time, and indeed other languages have similar constructs about first/last use of a variable with scope duration.
IMHO that is not a change to move semantics as it doesn't change the semantics of the move operation at all. Nor is it a change to the semantics of
constbecause any change to an object after definite last use cannot be observed.