================
@@ -0,0 +1,118 @@
+.. title:: clang-tidy - readability-redundant-nested-if
+
+readability-redundant-nested-if
+===============================
+
+Finds nested ``if`` statements that can be merged by combining their conditions
+with ``&&``.
+
+Example:
+
+.. code-block:: c++
+
+  if (a) {
+    if (b) {
+      work();
+    }
+  }
+
+becomes
+
+.. code-block:: c++
+
+  if ((a) && (b)) {
+    work();
+  }
+
+The check can merge longer chains as well:
+
+.. code-block:: c++
+
+  if (a) {
+    if (b) {
+      if (c) {
+        work();
+      }
+    }
+  }
+
+becomes
+
+.. code-block:: c++
+
+  if ((a) && (b) && (c)) {
+    work();
+  }
+
+The check also supports outer declaration conditions in C++17 and later:
+
+.. code-block:: c++
+
+  if (bool x = ready()) {
+    if (can_run()) {
+      work();
+    }
+  }
+
+becomes
+
+.. code-block:: c++
+
+  if (bool x = ready(); x && (can_run())) {
+    work();
+  }
+
+Safety rules
+------------
+
+The check only transforms chains where:
+
+- Neither outer nor nested ``if`` has an ``else`` branch.
+- Nested merged ``if`` statements do not use condition variables.
----------------
EugeneZelenko wrote:

```suggestion

- Nested merged ``if`` statements do not use condition variables.
```

Same for other list entries.

https://github.com/llvm/llvm-project/pull/181558
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to