[clang-tools-extra] b9852ff - [clang-tidy] Ignore requires expr in bugprone-assignment-in-if-condition (#98079)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 12 10:58:49 PDT 2024
Author: Piotr Zegar
Date: 2024-07-12T19:58:45+02:00
New Revision: b9852ff5fc4986c6cf8c4ecd1eb5726d55a08ea3
URL: https://github.com/llvm/llvm-project/commit/b9852ff5fc4986c6cf8c4ecd1eb5726d55a08ea3
DIFF: https://github.com/llvm/llvm-project/commit/b9852ff5fc4986c6cf8c4ecd1eb5726d55a08ea3.diff
LOG: [clang-tidy] Ignore requires expr in bugprone-assignment-in-if-condition (#98079)
Ignore assignments in RequiresExpr, to avoid false positives.
Fixes #97972
Added:
clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition-cxx20.cpp
Modified:
clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
index 9e56ee66a064f..e03cac6c5fd83 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
@@ -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);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index bde096b9eebd9..c1fa502534ea5 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -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
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition-cxx20.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition-cxx20.cpp
new file mode 100644
index 0000000000000..b332b2e49ec7f
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition-cxx20.cpp
@@ -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; }) {
+ }
+}
More information about the cfe-commits
mailing list