Steven Schveighoffer wrote:
If you find the above unsurprising, you are in the minority. I find it surprising, and invalid that anyone would write code this way. People simply just don't do that normally. It's just written to demonstrate a point that the compiler does not guarantee anything via const, it's guaranteed by convention. The compiler simply helps you follow the convention.

Ok, I see what you mean now. Your code is relying on there being a mutable alias of the same object.

This is not surprising behavior. It is explicit in how const is defined. It makes sense that const does not have immutable behavior, because otherwise there wouldn't be both const and immutable type constructors.

You're wrong in saying the compiler doesn't guarantee anything with const. I listed the things it does guarantee.

Reply via email to