3 ms·
>It is linguistically guaranteed to be non-mutating - const-casts excepted of course. Technically even after const-casting, if it was declared const then it's
by logicchains 9y ago
>It is linguistically guaranteed to be non-mutating - const-casts excepted of course.
Technically even after const-casting, if it was declared const then it's still not possible to mutate it, as doing so is undefined behaviour. "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." - http://en.cppreference.com/w/cpp/language/const_cast http://en.cppreference.com/w/cpp/language/const_cast
It could for instance have been stored in non-writable memory, so any attempt to write to it will instantly segfault. This is one of my favourite things about C++ as people engaging in terrible programming practices like const-casting a const object get their just desserts, so to speak.