llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-tidy] readability-implicit-bool-conversion.AllowPointerConditions not honored

Open adesitter opened this issue 2 years ago • 2 comments

$ cat bool1.cpp 
#include <cstdio>
bool OpenR(const char* filename) {
  auto* file_ = fopen(filename, "rb");
  return !file_;
}
$ /usr/local/clang-17/bin/clang-tidy -config="{Checks: '-*,readability-implicit-bool-conversion', CheckOptions: [{key: readability-implicit-bool-conversion.AllowPointerConditions, value: true}, {key: readability-implicit-bool-conversion.AllowIntegerConditions, value: true}]}" bool1.cpp --
1 warning generated.
/tmp/bool1.cpp:4:11: warning: implicit conversion 'FILE *' (aka '_IO_FILE *') -> bool [readability-implicit-bool-conversion]
    4 |   return !file_;
      |          ~^    
      |                 == nullptr

Since readability-implicit-bool-conversion.AllowPointerConditions is set to true, the warning should not be emitted.

adesitter avatar Jan 25 '24 13:01 adesitter

Actually no bug here, as this isn't condition, option AllowPointerConditions covers only conditions, like "if (!file_)" and so on.

PiotrZSL avatar Jan 25 '24 13:01 PiotrZSL

This makes this check not very useful for a code base where conversions between integral types and bool should be explicit but where conversions from pointer to bool are allowed.

adesitter avatar Jan 25 '24 14:01 adesitter