[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

Bhuminjay Soni via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 12 09:09:01 PST 2024


================
@@ -0,0 +1,31 @@
+.. title:: clang-tidy - readability-use-std-min-max
+
+readability-use-std-min-max
+===========================
+
+Replaces certain conditional statements with equivalent ``std::min`` or ``std::max`` expressions, 
+improving readability and promoting the use of standard library functions.
+Note: this transformation may impact performance in performance-critical code due to potential 
+additional stores compared to the original if statement.
+
+Examples:
+
+Before:
+
+.. code-block:: c++
+
+  void foo() {
+  int a, b;
+  if (a < b)
+    a = b;
+  }
+
----------------
11happy wrote:

sorry I am not able to get where is the bracket missing

https://github.com/llvm/llvm-project/pull/77816


More information about the cfe-commits mailing list