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

readability-redundant-parentheses false positive on requires-clause

Open philipp-hackerman opened this issue 3 months ago • 3 comments

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); }

philipp-hackerman avatar Aug 26 '26 15:08 philipp-hackerman

@llvm/issue-subscribers-clang-tidy

Author: philipp-hackerman

`clang-tidy --checks='-*,readability-redundant-parentheses' test.cpp -- -std=c++20`

What happens: the check reports "redundant parentheses around expression" on (ok&lt;T&gt;()) inside a requires-clause and offers to remove them. But ok&lt;T&gt;() is a postfix-expression, not a primary-expression — the parentheses are mandatory syntax here. Applying the fix produces requires ok&lt;T&gt;(), which is ill-formed ("parentheses are required around this expression in a requires clause").

Reproducer:

template &lt;typename T&gt;
constexpr bool valid() { return sizeof(T) &gt;= 1; }

template &lt;typename T&gt;
requires (valid&lt;T&gt;())
constexpr T forward(T val) {
  return val;
}

int demo() { return forward&lt;int&gt;(99); }

https://godbolt.org/z/YobK4z47Y

vbvictor avatar Aug 26 '26 19:08 vbvictor

Can give this a try

davidmenggx avatar Aug 27 '26 15:08 davidmenggx