[Bug c++/86761] Code corruption with missing pointer return

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jul 31 21:01:00 GMT 2018


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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Hans de Jong from comment #0)
> Code runs fine on GCC, despite the warning.

In C the behaviour of a non-void function that fails to return anything is only
undefined if the return value is used by the caller.

> Code runs only on G++ with no optimizations. Unpredictable fatal behaviour
> occurs on various optimization levels.

In C++ standard it's undefined behaviour if a non-void function fails to return
anything, even if the return value is not used by the caller. 

Because you're compiling C++ the behaviour is undefined. The compiler can
assume that the function is never called, because if it was called it would
produce undefined behaviour.

> hard to track down since the function "setFlags" was nested 3 levels down in
> the code.

I don't understand how that can make any difference, the warning tells you
where the missing return is. That's the location you need to fix.


More information about the Gcc-bugs mailing list