[clang-tidy] `readability-implicit-bool-conversion` is too noisy by default
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Out-of-the-box the `readability-implicit-bool-conversion` is way too noisy to be usable.
`AllowIntegerConditions` and `AllowPointerConditions` should be set to `true` to be begin with as those are common patterns.
With those patterns allowed I would expect that I only get assignments where an implicit conversion is allowed (which might actually indicate an unintentional behavior so that pattern rather belongs into `misc-*` or `bugprone-*`). But usages in `return` statements will still produce warnings.
```cpp
bool f2(int i, int* i1, int& i2)
{
if (i) {
return i;
}
if (i1) {
return *i1;
}
return i2;
}
```
```
:4:16: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]
4 | return i;
| ^
| != 0
:7:16: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]
7 | return *i1;
| ^
| != 0
:9:12: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]
9 | return i2;
| ^
| != 0
```
https://godbolt.org/z/jnWjbea13
This is also a very common pattern but it is not a condition and more akin to an assignment. So maybe that case should get additional (off by default) options. This is already tracked in #79447.
It is possible that there are more cases but it is hard to tell with the amount of warnings the check currently produces. There is also more related issues:
#63450
#36323
Contributor guide
Research direction
Start at the clang-tidy readability-implicit-bool-conversion check and review the AllowIntegerConditions and AllowPointerConditions options, then compare the examples and linked issues #79447, #63450, and #36323. Done means the default warning volume and return-statement behavior match an agreed scope, with coverage for the reported cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100