https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89056
--- Comment #6 from Darryl Okahata <darryl_okahata at keysight dot com> --- (OK, at this point, I'm just whinging, so please feel free to ignore this.) I just wish the C++ standard instead just allowed an undefined value to be returned, instead of generating bad optimized code. With the current state, I either have to add compiler-specific extensions or unreachable return statements to insure that correct code is generated (unexpected and violates POLA). The issue is that g++ (understandably) can't always detect if there is always a proper return statement (execution can never hit the end of the function). Grossly-oversimplified example (real code is much more complicated): enum E { A, B }; bool bah(const enum E a) { if (a == A) return false; if (a == B) return true; } Compiling with (8.2.0): g++ -S -O badbad.cc gives: badbad.cc: In function 'bool bah(E)': badbad.cc:10:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ Understandable, as I don't expect g++ to figure out complicated code machinations. However, I don't know all the circumstances under which this warning means that g++ is generating bad code. As a result, I have to add unreachable return statements to insure that g++ does not generate bad optimized code. Our code runs on multiple platforms, and so I'd rather avoid the use of g++ extensions (e.g., __builtin_unreachable() or attributes) and cluttering #ifdefs. Adding an unreachable return is undesirable but simple and portable: enum E { A, B }; bool bah(const enum E a) { if (a == A) return false; if (a == B) return true; return false; // UNREACHABLE }