https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106696

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|FIXED                       |INVALID

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
No, if code invokes undefined behavior, anything can happen, it is undefined
what exactly.
To help debugging, g++ 13 introduces -funreachable-traps and will emit a trap
instruction in such cases by default at -O0 or -Og (or when the user uses the
option).
Otherwise, such spots are internally handled as __builtin_unreachable, which is
a special builtin which says that it is UB to reach it.  That can result in
optimizing code leading to it, e.g. if you have
void *foo (int x) { if (x < 35) return ""; }
then it can optimize away the comparison and always return "" (because anything
else is UB), similarly if a function has a switch which doesn't fall through
except for a few cases, it can assume those will not happen in a correct
program, etc.
Because of the C++ vs. C differences, -Wreturn-type warning is on by default in
C++ while it is only included in -Wall for C, users just shouldn't ignore this
warning unless it is really impossible to reach it at runtime.

Reply via email to