readability-redundant-parentheses false positive on requires-clause
clang-tidy --checks='-*,readability-redundant-parentheses' test.cpp -- -std=c++20
What happens: the check reports "redundant parentheses around expression" on (ok<T>()) inside a requires-clause and offers to remove them. But ok<T>() is a postfix-expression, not a primary-expression — the parentheses are mandatory syntax here. Applying the fix produces requires ok<T>(), which is ill-formed ("parentheses are required around this expression in a requires clause").
Reproducer:
template <typename T>
constexpr bool valid() { return sizeof(T) >= 1; }
template <typename T>
requires (valid<T>())
constexpr T forward(T val) {
return val;
}
int demo() { return forward<int>(99); }
@llvm/issue-subscribers-clang-tidy
Author: philipp-hackerman
What happens: the check reports "redundant parentheses around expression" on (ok<T>()) inside a requires-clause and offers to remove them. But ok<T>() is a postfix-expression, not a primary-expression — the parentheses are mandatory syntax here. Applying the fix produces requires ok<T>(), which is ill-formed ("parentheses are required around this expression in a requires clause").
Reproducer:
template <typename T>
constexpr bool valid() { return sizeof(T) >= 1; }
template <typename T>
requires (valid<T>())
constexpr T forward(T val) {
return val;
}
int demo() { return forward<int>(99); }
https://godbolt.org/z/YobK4z47Y
Can give this a try