4 ms·
More like: switch (e) { case A: foo(); break; case B: bar(); break; } std::unreachable(); instead of: switch (e) { case A:
by planede 2y ago
More like:
switch (e) {
case A:
foo(); break;
case B:
bar(); break;
}
std::unreachable();
instead of:
switch (e) {
case A:
foo(); break;
case B:
bar(); break;
default:
std::unreachable();
}
The former is more likely to produce a warning if there is an enumeration C that you forgot to handle, or you added an enumeration C and missed a switch-case to update.
edit:
duh, it's supposed to be returns here instead of breaks.
- flohofwoe 2y agoBut then all case branches hit the std::unreachable. How can that work in practice?
- gravescale 2y agoI think it's supposed to be a return not a break.