[PATCH] D22507: Clang-tidy - Enum misuse check

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 21 08:18:00 PDT 2016


aaron.ballman added a subscriber: aaron.ballman.

================
Comment at: clang-tidy/misc/EnumMisuseCheck.cpp:31
@@ +30,3 @@
+// Stores a min and a max value which describe an interval.
+struct ValueRange {
+  llvm::APSInt MinVal, MaxVal;
----------------
I think this class can be replaced by `std::minmax_element()` over the `EnumDec->enumerators()` and then grabbing the actual values out of the resulting `std::pair`.

================
Comment at: clang-tidy/misc/EnumMisuseCheck.cpp:59
@@ +58,3 @@
+
+bool isMaxValAllBitSet(const EnumDecl *EnumDec) {
+  for (auto I = EnumDec->enumerator_begin(), E = EnumDec->enumerator_end();
----------------
This function doesn't do what is described. It appears to be checking if the last value in the enumeration has all its bits set, not if the max value has all the bits set. e.g., it won't check:
```
enum E {
  MaxValue = 0xFFFFFFFF,
  First = 0,
  Second
};
```

================
Comment at: clang-tidy/misc/EnumMisuseCheck.h:24
@@ +23,3 @@
+class EnumMisuseCheck : public ClangTidyCheck {
+    const bool IsStrict;
+
----------------
hokein wrote:
> Put it to private member.
It is a private member already. I think this usage is fine.


https://reviews.llvm.org/D22507





More information about the cfe-commits mailing list