Skip to content

Commit b9852ff

Browse files
authored
[clang-tidy] Ignore requires expr in bugprone-assignment-in-if-condition (#98079)
Ignore assignments in RequiresExpr, to avoid false positives. Fixes #97972
1 parent a31b3de commit b9852ff

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ void AssignmentInIfConditionCheck::check(
3939
return true;
4040
}
4141

42+
// Dont traverse into any requires expressions.
43+
bool TraverseRequiresExpr(RequiresExpr *,
44+
DataRecursionQueue * = nullptr) {
45+
return true;
46+
}
47+
4248
bool VisitBinaryOperator(BinaryOperator *BO) {
4349
if (BO->isAssignmentOp())
4450
Check.report(BO);

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ Changes in existing checks
232232
<clang-tidy/checks/bugprone/assert-side-effect>` check by detecting side
233233
effect from calling a method with non-const reference parameters.
234234

235+
- Improved :doc:`bugprone-assignment-in-if-condition
236+
<clang-tidy/checks/bugprone/assignment-in-if-condition>` check by ignoring
237+
assignments in the C++20 ``requires`` clause.
238+
235239
- Improved :doc:`bugprone-casting-through-void
236240
<clang-tidy/checks/bugprone/casting-through-void>` check by ignoring casts
237241
where source is already a ``void``` pointer, making middle ``void`` pointer
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %check_clang_tidy -std=c++20 %s bugprone-assignment-in-if-condition %t
2+
3+
void testRequires() {
4+
if constexpr (requires(int &a) { a = 0; }) {
5+
}
6+
}

0 commit comments

Comments
 (0)