Originally Posted by
grumpy
According to the letter of the standard, the compiler is not required to catch this. The result is undefined behaviour (which means anything is allowed to happen).
In practice, good quality compilers catch some of the simple and obvious cases.
The reason such things are undefined behaviour is that it is very difficult (and in worst cases, such as when the behaviour results from user inputs, impossible) for a compiler working alone to catch the "not simple and not obvious cases".