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

Piotr Zegar via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 15 09:44:18 PST 2024


================
@@ -0,0 +1,27 @@
+// RUN: %check_clang_tidy %s readability-ConditionalToStdMinMax %t
+
+void foo() {
+  int value1,value2;
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: use std::max instead of < [readability-ConditionalToStdMinMax]
+  if (value1 < value2)
+    value1 = value2; // CHECK-FIXES: value1 = std::max(value1, value2);
----------------
PiotrZSL wrote:

Fixes doesn't work "per line", they matched across entire file, so you can put them just right under CHECK-MESSAGES, or at least put them in new line.

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


More information about the cfe-commits mailing list