Bug 1473453 - Part 3: Enable clang-tidy's misc-bool-pointer-implicit-conversion warning. r?andi draft
authorChris Peterson <cpeterson@mozilla.com>
Wed, 04 Jul 2018 19:30:33 -0700
changeset 814374 870fbb28a158fc86ccb534fa58041cdf059a1e02
parent 814373 0de6b76c3614bb60408fce2236f98a0cae348bb1
push id115173
push usercpeterson@mozilla.com
push dateThu, 05 Jul 2018 03:25:42 +0000
reviewersandi
bugs1473453
milestone63.0a1
Bug 1473453 - Part 3: Enable clang-tidy's misc-bool-pointer-implicit-conversion warning. r?andi And add a clang-tidy test. MozReview-Commit-ID: KmCgrUcV0Lm
tools/clang-tidy/config.yaml
tools/clang-tidy/test/misc-bool-pointer-implicit-conversion.cpp
tools/clang-tidy/test/misc-bool-pointer-implicit-conversion.json
--- a/tools/clang-tidy/config.yaml
+++ b/tools/clang-tidy/config.yaml
@@ -29,16 +29,18 @@ clang_checkers:
   - name: clang-analyzer-security.insecureAPI.UncheckedReturn
     publish: !!bool yes
   - name: clang-analyzer-security.insecureAPI.vfork
     publish: !!bool yes
   - name: misc-argument-comment
     publish: !!bool yes
   - name: misc-assert-side-effect
     publish: !!bool yes
+  - name: misc-bool-pointer-implicit-conversion
+    publish: !!bool yes
   - name: misc-forward-declaration-namespace
     # Name with clang tidy 6.0. We are currently using 5.0
     # - name: bugprone-forward-declaration-namespace
     publish: !!bool yes
   - name: misc-suspicious-missing-comma
     publish: !!bool yes
   - name: misc-suspicious-semicolon
     publish: !!bool yes
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/misc-bool-pointer-implicit-conversion.cpp
@@ -0,0 +1,20 @@
+// https://clang.llvm.org/extra/clang-tidy/checks/bugprone-bool-pointer-implicit-conversion.html
+
+bool test(bool* pointer_to_bool, int* pointer_to_int)
+{
+  if (pointer_to_bool) { // warning for pointer to bool
+  }
+
+  if (pointer_to_int) { // no warning for pointer to int
+  }
+
+  if (!pointer_to_bool) { // no warning, but why not??
+  }
+
+  if (pointer_to_bool != nullptr) { // no warning for nullptr comparison
+  }
+
+  // no warning on return, but why not??
+  // clang-tidy bug: https://bugs.llvm.org/show_bug.cgi?id=38060
+  return pointer_to_bool;
+}
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/misc-bool-pointer-implicit-conversion.json
@@ -0,0 +1,1 @@
+"[[\"warning\", \"dubious check of 'bool *' against 'nullptr', did you mean to dereference it?\", \"misc-bool-pointer-implicit-conversion\"]]"
\ No newline at end of file