[clang-tidy] Ignore requires expr in bugprone-assignment-in-if-condition (#98079)
Ignore assignments in RequiresExpr, to avoid false positives. Fixes #97972
This commit is contained in:
parent
a31b3de928
commit
b9852ff5fc
@ -39,6 +39,12 @@ void AssignmentInIfConditionCheck::check(
|
||||
return true;
|
||||
}
|
||||
|
||||
// Dont traverse into any requires expressions.
|
||||
bool TraverseRequiresExpr(RequiresExpr *,
|
||||
DataRecursionQueue * = nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VisitBinaryOperator(BinaryOperator *BO) {
|
||||
if (BO->isAssignmentOp())
|
||||
Check.report(BO);
|
||||
|
@ -232,6 +232,10 @@ Changes in existing checks
|
||||
<clang-tidy/checks/bugprone/assert-side-effect>` check by detecting side
|
||||
effect from calling a method with non-const reference parameters.
|
||||
|
||||
- Improved :doc:`bugprone-assignment-in-if-condition
|
||||
<clang-tidy/checks/bugprone/assignment-in-if-condition>` check by ignoring
|
||||
assignments in the C++20 ``requires`` clause.
|
||||
|
||||
- Improved :doc:`bugprone-casting-through-void
|
||||
<clang-tidy/checks/bugprone/casting-through-void>` check by ignoring casts
|
||||
where source is already a ``void``` pointer, making middle ``void`` pointer
|
||||
|
@ -0,0 +1,6 @@
|
||||
// RUN: %check_clang_tidy -std=c++20 %s bugprone-assignment-in-if-condition %t
|
||||
|
||||
void testRequires() {
|
||||
if constexpr (requires(int &a) { a = 0; }) {
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user