[clang-tools-extra] [clang-tidy] Add modernize-use-std-tie check (PR #191218)

Daniil Dudkin via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 9 16:53:51 PDT 2026


================
@@ -0,0 +1,45 @@
+// RUN: %check_clang_tidy %s modernize-use-std-tie %t
+
+#include <tuple>
+
+struct A {
+    int n;
+    double s; 
+    float w;
+    float v;
+    float d() const noexcept { return w / v; }
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:6: warning: use std::tie to implement lexicographical comparison [modernize-use-std-tie]
+bool operator<(const A& lhs, const A& rhs) noexcept
+{
+    if (lhs.n != rhs.n) {
+        return lhs.n < rhs.n;
+    } else if (lhs.s != rhs.s) {
+        return lhs.s < rhs.s;
+    }
+    return lhs.d() < rhs.d();
+}
+// CHECK-FIXES: bool operator<(const A& lhs, const A& rhs) noexcept
+// CHECK-FIXES-NEXT: {
+// CHECK-FIXES-NEXT:     const auto lhs_d = lhs.d();
+// CHECK-FIXES-NEXT:     const auto rhs_d = rhs.d();
+// CHECK-FIXES-NEXT:     return std::tie(lhs.n, lhs.s, lhs_d) < std::tie(rhs.n, rhs.s, rhs_d);
----------------
unterumarmung wrote:

Why do you introduce new variables instead of just calling the method?

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


More information about the cfe-commits mailing list