You can call it as a const function for an object that is not a constant, but for various reasons.
The volatile qualifier makes this parameter implicitly treated as a pointer to a mutable object.
Essentially, this means that the semantics of mutable objects will be applied when accessing the element (s) of the object's data. Any reading of x cannot be optimized, even if the compiler can prove that there is no last record after the last read.
Naturally, if the object is not really mutable, the func body is still correct, although not as optimized as it can be. So you can call it just fine.
source share