[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:
Piotr Zegar 2024-07-12 19:58:45 +02:00 committed by GitHub
parent a31b3de928
commit b9852ff5fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 0 deletions

View File

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

View File

@ -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

View File

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