[PATCH] D30896: [Clang-tidy] add check misc-prefer-switch-for-enums
Jonathan B Coe via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 14 03:21:08 PDT 2017
jbcoe added a comment.
@aaron.ballman
re: "perhaps the check could be relaxed to only consider cases where you have multiple if/else if clauses".
Sadly this does not satisfy my use case where most of the time a single enum value is used.
enum class animal_kind { herbivore, carnivore };
if(k == animal_kind:: carnivore) { ... }
I now add `omnivore` and play 'hunt-the-if' knowing anything I miss will be a bug.
---
re: "There are definitely times when using == or != for a specific value is *way* cleaner than using a switch statement".
I **totally** agree. That's why I want this check. People don't remember to use `switch` for enums because it's harder and looks uglier.
Perhaps this check should not go in `misc` as it might be better to have it opt-in? I know I want it in one code-base I work on.
---
@xazax.hun
re: "Also, maybe the readability module would be a better place for this check."
I like the idea of it not being in `misc` as it should be opt-in. It really does little to enhance `readability` though. Should we add a `maintainability` module? I'm not sure where this check should live.
Repository:
rL LLVM
https://reviews.llvm.org/D30896
More information about the cfe-commits
mailing list