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

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 5 00:33:00 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL348341: Fix a false positive in misplaced-widening-cast (authored by JonasToth, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55255?vs=176604&id=176769#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55255

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


Index: clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
+++ clang-tools-extra/trunk/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;
   }
 
Index: clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-widening-cast-explicit-only.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-misplaced-widening-cast-explicit-only.cpp
+++ clang-tools-extra/trunk/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);
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55255.176769.patch
Type: text/x-patch
Size: 1518 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181205/0b2d9e74/attachment.bin>


More information about the cfe-commits mailing list