https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100700
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to gnzlbg from comment #2) > Until C++17, creating an enum value that's out-of-range of the enum was > unspecified behavior. In C++ standard >= 17 (e.g. -std=c++17), this became > undefined behavior. With GCC it depends on the -fstrict-enums option. > The only way in which "h(E e)" can fall of its end in C++>=17 is if the > program already had undefined behavior. That's true if you use -fstrict-enums, and if you do that, there's no warning. Without that option GCC does not treat (E)2 as undefined, and so it considers it possible for the function to be called with that value.