[PATCH] [clang-tidy] Add a checker for implicit bool conversion of a bool*.

Alexander Kornienko alexfh at google.com
Thu Jul 10 07:37:42 PDT 2014


================
Comment at: clang-tidy/misc/BoolPointerImplicitConversion.cpp:51
@@ +50,3 @@
+  auto DeclRef = ignoringParenImpCasts(declRefExpr(to(equalsNode(D))));
+  if (!match(findAll(
+                 unaryOperator(hasOperatorName("*"), hasUnaryOperand(DeclRef))),
----------------
As discussed off-the-list, presence of other pointer-specific operations could be used to avoid some false positives: use of "delete" and passing the value as an argument of a function taking bool*, reference to bool* or anything that bool* can be converted to, but bool can't (void*, maybe something else).

================
Comment at: clang-tidy/misc/BoolPointerImplicitConversion.cpp:56
@@ +55,3 @@
+             *Result.Context).empty() ||
+      !match(findAll(callExpr(hasAnyArgument(DeclRef))), *If, *Result.Context)
+           .empty())
----------------
I'd check here the type of the corresponding parameter. If it is "bool", this would be a strong indicator of a true positive.

================
Comment at: test/clang-tidy/misc-bool-pointer-implicit-conversion.cpp:32
@@ +31,3 @@
+// Can't fix this.
+// CHECK-FIXES: CHECK {
+  }
----------------
How is this supposed to check the right thing?

================
Comment at: test/clang-tidy/misc-bool-pointer-implicit-conversion.cpp:37
@@ +36,3 @@
+
+// CHECK-MESSAGES-NOT: dubious
+
----------------
I'd go for a "CHECK-MESSAGES-NOT: warning:", at least for consistency.

http://reviews.llvm.org/D4458






More information about the cfe-commits mailing list