[clang] [clang-tools-extra] [llvm] 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
Sun Jan 28 13:16:11 PST 2024


================
@@ -0,0 +1,230 @@
+// RUN: %check_clang_tidy %s readability-use-std-min-max %t
+#define MY_MACRO_MIN(a, b) ((a) < (b) ? (a) : (b))
+
+constexpr int myConstexprMin(int a, int b) {
+  return a < b ? a : b;
+}
+
+constexpr int myConstexprMax(int a, int b) {
+  return a > b ? a : b;
+}
+
+#define MY_IF_MACRO(condition, statement) \
+  if (condition) {                        \
+    statement                             \
+  }
+
+class MyClass {
+public:
+  int member1;
+  int member2;
+};
+
+template<typename T>
+
+void foo(T value7) {
+  int value1,value2,value3;
+  short value4;
+  unsigned int value5;
+  unsigned char value6;
+  const int value8 = 5;
+  volatile int value9 = 6;
+  MyClass obj;
+
----------------
PiotrZSL wrote:

This isn't C, put variables closer to usage...

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


More information about the cfe-commits mailing list