[Bug c++/96181] Missing return statement now leads to crashes

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Jul 13 11:26:10 GMT 2020


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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Arturo Laurenzi from comment #0)
> Now, I understand the code snipped is probably broken. However, this change
> breaks old code that would work just fine by ignoring the undefined return
> value.

It didn't work fine, it had undefined behaviour. It just appeared to work fine.

GCC clearly warns you about it:

96181.C: In function ‘bool func(int)’:
96181.C:9:1: warning: no return statement in function returning non-void
[-Wreturn-type]
    9 | }  // missing return statement
      | ^

If you're ignoring such warnings routinely maybe you should use
-Werror=return-type to force yourself to fix them.


More information about the Gcc-bugs mailing list