llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.24k stars 11.66k forks source link

clang-tidy bool-pointer-implicit-conversion does not warn about `return pointer_to_bool;` #37408

Open cpeterso opened 6 years ago

cpeterso commented 6 years ago
Bugzilla Link 38060
Version unspecified
OS All
CC @dwblaikie

Extended Description

clang-tidy logs only one bool-pointer-implicit-conversion warning for following code:

bool test(bool* pointer_to_bool) { if (pointer_to_bool) { // warning, as expected :) }

return pointer_to_bool; // no warning, but why not? :(

}

The return pointer_to_bool statement uses pointer_to_bool in a boolean expression but doesn't trigger a warning.

clang-tidy --checks="-*,misc-bool-pointer-implicit-conversion" bool-pointer-implicit-conversion.cpp

bool-pointer-implicit-conversion.cpp:5:7: warning: dubious check of 'bool ' against 'nullptr', did you mean to dereference it? [misc-bool-pointer-implicit-conversion] if (pointer_to_bool) { // warning ^

https://clang.llvm.org/extra/clang-tidy/checks/bugprone-bool-pointer-implicit-conversion.html

cpeterso commented 6 years ago

if (!pointer_to_bool) {} does not trigger a bool-pointer-implicit-conversion warning, either.