[PATCH] D55255: Fix a false positive in misplaced-widening-cast

Daniel Krupp via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 4 04:46:41 PST 2018


dkrupp updated this revision to Diff 176604.
dkrupp added a comment.

Comments addressed. Please commit if looks good, I don't have commit rights.
Thanks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55255/new/

https://reviews.llvm.org/D55255

Files:
  clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
  test/clang-tidy/bugprone-misplaced-widening-cast-explicit-only.cpp


Index: test/clang-tidy/bugprone-misplaced-widening-cast-explicit-only.cpp
===================================================================
--- test/clang-tidy/bugprone-misplaced-widening-cast-explicit-only.cpp
+++ test/clang-tidy/bugprone-misplaced-widening-cast-explicit-only.cpp
@@ -62,3 +62,21 @@
   enum Type {};
   static char *m_fn1() { char p = (Type)(&p - m_fn1()); }
 };
+
+enum DaysEnum {
+  MON,
+  TUE,
+  WED,
+  THR,
+  FRI,
+  SAT,
+  SUN
+};
+
+// Do not warn for int to enum casts.
+void nextDay(DaysEnum day) {
+  if (day < SUN)
+    day = (DaysEnum)(day + 1);
+  if (day < SUN)
+    day = static_cast<DaysEnum>(day + 1);
+}
Index: clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
===================================================================
--- clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
+++ clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
@@ -213,8 +213,9 @@
         dyn_cast<BuiltinType>(CastType->getUnqualifiedDesugaredType());
     const auto *CalcBuiltinType =
         dyn_cast<BuiltinType>(CalcType->getUnqualifiedDesugaredType());
-    if (CastBuiltinType && CalcBuiltinType &&
-        !isFirstWider(CastBuiltinType->getKind(), CalcBuiltinType->getKind()))
+    if (!CastBuiltinType || !CalcBuiltinType)
+      return;
+    if (!isFirstWider(CastBuiltinType->getKind(), CalcBuiltinType->getKind()))
       return;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55255.176604.patch
Type: text/x-patch
Size: 1374 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181204/d52fdb72/attachment-0001.bin>


More information about the cfe-commits mailing list