Case 1 does not change anything; case 2 changes the variable. It seems pretty obvious to me!
Changing a variable requires that it is not constant, you need to have a mutable state, and the ++x expression changes that state. Since the constexpr function can be evaluated at compile time, there is no "variable" on it, because no code is executed, because we are not yet at run time.
As others have said, C ++ 14 allows constexpr functions constexpr change their local variables, allowing more interesting things, such as for loops. There is still no "variable" there, so the compiler should act as a simplified interpreter at compile time and allow manipulation during compilation with limited forms of the local state. This is a pretty significant change from the more limited C ++ 11 rules.
source share