[clang-tidy] inconsistent handling of comparisons in `readability-redundant-parentheses`
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
```cpp
#include
#include
bool f1()
{
std::map m;
auto it = m.find(0);
return (it != m.cend());
}
bool f2(int i)
{
return (i == 0); // no warning
}
int f3(const std::string& s)
{
return (s >= "0");
}
```
```
:8:12: warning: redundant parentheses around expression [readability-redundant-parentheses]
8 | return (it != m.cend());
| ^ ~
:18:12: warning: redundant parentheses around expression [readability-redundant-parentheses]
18 | return (s >= "0");
| ^ ~
```
https://godbolt.org/z/EvPde1hbq
I would have expected the warning in all three cases.
*But* I think having the parentheses around a comparison might actually have better readability (especially if there is multiple conditions) so I would like to have an option to control that.
Contributor guide
Research direction
Reproduce the three examples with clang-tidy's readability-redundant-parentheses check, using the linked Compiler Explorer case as a reference. Trace the check's handling of comparison expressions and determine the intended option behavior; done means the three cases are handled consistently and the requested control over comparison parentheses is defined and covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100