readability-redundant-parentheses false positive on requires-clause
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
`clang-tidy --checks='-*,readability-redundant-parentheses' test.cpp -- -std=c++20`
What happens: the check reports "redundant parentheses around expression" on (`ok()`) inside a requires-clause and offers to remove them. But `ok()` is a postfix-expression, not a primary-expression — the parentheses are mandatory syntax here. Applying the fix produces requires `ok()`, which is ill-formed ("parentheses are required around this expression in a requires clause").
Reproducer:
```c++
template
constexpr bool valid() { return sizeof(T) >= 1; }
template
requires (valid())
constexpr T forward(T val) {
return val;
}
int demo() { return forward(99); }
```
Contributor guide
Research direction
Start by running the stated clang-tidy command on test.cpp with C++20 enabled, then inspect the readability-redundant-parentheses check. Use the requires-clause reproducer to verify that mandatory parentheses are not reported or removed, and confirm the corrected behavior by compiling the resulting code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100