It is often desirable (example: [1]) to have a switch statement over an enum with one case for every value:
enum MyEnum {
VAL_1,
VAL_2
};
int f(MyEnum val) {
switch (val) {
case VAL_1:
return 1;
case VAL_2:
return 2;
}
}
This forces every enum value to be accounted for at compile-time. If you add a value to the enum without adding it to such a switch statement, you get `error: enumeration value 'VAL_3' not handled in switch [-Werror,-Wswitch]`.
However, this fails to compile on the Windows bots. Fixing it always requires extra two round-trips for me:
- Add a `default:` case with `NOTREACHED()`.
- *Still* get a Windows error.
- Add a bogus return statement (returning the "safest" enum value) after `NOTREACHED()`.
- Passes trybots.
It would be nice if all of these situations compiled consistently across platforms. It would be nicest if the initial code snippet above works on all platforms, though.
[1] https://cs.chromium.org/chromium/src/content/browser/devtools/protocol/security_handler.cc
Comment 1 by lgar...@chromium.org
, Sep 7 2017