[PATCH] D30896: [CLANG-TIDY] add check misc-prefer-switch-for-enums
Jonas Toth via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 13 09:03:50 PDT 2017
JonasToth added a comment.
I like that check. But I think it could take another feature.
In my opinion it would be valueable to check if enums are compared against ints as well.
For example
enum Kind k = Kind::a;
if (k == 3) { /* something */ }
This usecase is not specially considered here, but i think that check would be the right place. Maybe it is already covered by your matcher, since you check for everything that compares against enums.
If yes, additional diagnostics would be nice.
This check should be added to the ReleaseNotes as well.
================
Comment at: clang-tools-extra/clang-tidy/misc/PreferSwitchForEnumsCheck.cpp:21
+void PreferSwitchForEnumsCheck::registerMatchers(MatchFinder *Finder) {
+ // FIXME: Add matchers.
+ Finder->addMatcher(
----------------
remove `FIXME`
================
Comment at: clang-tools-extra/clang-tidy/misc/PreferSwitchForEnumsCheck.cpp:27
+ hasLHS(declRefExpr(hasDeclaration(enumConstantDecl()))))))
+ .bind("x"),
+ this);
----------------
maybe a more telling name than `x` would be better?
================
Comment at: clang-tools-extra/test/clang-tidy/misc-prefer-switch-for-enums.cpp:3
+
+enum class kind { a, b, c, d };
+
----------------
maybe another test for non enum class values would be nice.
```
enum another_kind {e, f, g};
```
Repository:
rL LLVM
https://reviews.llvm.org/D30896
More information about the cfe-commits
mailing list