[Bug c++/87951] GCC warns about reaching end of non-void function when all switch is completely handled

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Dec 10 20:31:00 GMT 2018


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

--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It's not a useless warning. If I call your function from comment 7 like this, I
get undefined behaviour:

  CoverMyBases( Enum{2} );

Your switch is undefined for this code. That's what GCC is warning you about.
To tell GCC you will never call the function with any value except Enum::A or
Enum::B, add

  default: __builtin_unreachable();


More information about the Gcc-bugs mailing list