Yes, it's legal, but I can't recall that I have ever done it on purpose. Maybe that behaviour is defined just because it's better than the alternative of undefined behaviour?

Writing unit tests is a good recommendation though :-)