================
@@ -0,0 +1,75 @@
+.. title:: clang-tidy - misc-scope-reduction
+
+misc-scope-reduction
+====================
+
+Detects local variables in functions whose scopes can be minimized.
+
+Examples:
+
+.. code-block:: cpp
+
+    void test_deep_nesting() {
+      int deep = 1; // 'deep' can be declared in a smaller scope
+      if (true) {
+        if (true) {
+          if (true) {
+            if (true) {
+              int result = deep * 4;
+            }
+          }
+        }
+      }
+    }
+
+    void test_switch_case(int value) {
+      int result = 0; // 'result' can be declared in a smaller scope
+      switch (value) {
+        case 1:
+          result = 10;
+          break;
+        default:
+          break;
+      }
+    }
+
+    void test_for_loop_expressions() {
+      int i; // 'i' can be declared in the for-loop initialization
+      for (i = 0; i < 5; i++) {
+        // loop body
+      }
+    }
+
+Limitations
+-----------
+
+This checker cannot currently detect when a variable's previous value affects
----------------
EugeneZelenko wrote:

```suggestion
This check cannot currently detect when a variable's previous value affects
```

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

Reply via email to