[Bug c/96550] gcc is smart in figuring out a non-returning function.
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Aug 10 11:59:19 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96550
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The compiler can't diagnose this as an error (unless -Werror* is used), because
it is only an error if such code is ever called at runtime, which the compiler
can't determine at compile time.
That is why it is just a warning.
And, as an optimizing compiler, the compiler can and does optimize anything
that would be only reachable through that statement with UB.
This isn't an attempt to punish those who write broken code, but it actually
helps a lot in real-world code, something like that can happen frequently, but
usually in code that will not be actually encountered at runtime, just the
compiler can't prove that.
More information about the Gcc-bugs
mailing list