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
--- 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