https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81928
--- Comment #4 from Matthieu Brucher <matthieu.brucher at gmail dot com> --- I would agree if the debug and optimized versions had the same behavior. They do not. As such there should be a huge warning about the undefined behavior. And no, it's not valid code, it's an undefined behavior, you can do whatever you want with it. Outputting an error is a better solution, even adding a warning is. Silently optimizing an undefined behavior away is not.