https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107622
Bug ID: 107622 Summary: Missing optimization of switch-statement Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: klaus.doldinger64 at googlemail dot com Target Milestone: --- In the following example the default-case could not be reached. Therefore introducing std::unreachable() should be useless. But the compiler produces slightly better code with std::unreachable() as it removes one (unneccessary) comparison (tested for x86 and avr targets). volatile uint8_t o; enum class State : uint8_t {A, B, C}; void g(const State s) { switch(s) { case State::A: o = 10; break; case State::B: o = 11; break; case State::C: o = 12; break; default: // std::unreachable(); // __builtin_unreachable(); break; } }