This is a language lawyer question, not a good practice question.
Is the following code valid or undefined behaviour? A const object ends up calling a non-const function, but it doesn't actually modify the state of the object.
struct Bob
{
Bob() : a(0) {}
int& GetA()
{
return a;
}
const int& GetA() const
{
return const_cast<Bob&>(*this).GetA();
}
int a;
};
int main()
{
const Bob b;
int a = b.GetA();
}