[clang-tools-extra] [clang-tidy] Add new check `modernize-use-structured-binding` (PR #158462)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 3 07:59:13 PDT 2025


================
@@ -0,0 +1,622 @@
+// RUN: %check_clang_tidy -check-suffix=ALL,CPP20ORLATER -std=c++20-or-later %s modernize-use-structured-binding %t -- -- -I %S/Inputs/use-structured-binding/
+// RUN: %check_clang_tidy -check-suffix=ALL -std=c++17 %s modernize-use-structured-binding %t -- -- -I %S/Inputs/use-structured-binding/
+#include "fake_std_pair_tuple.h"
+
+template<typename T>
+void MarkUsed(T x);
+
+struct TestClass {
+  int a;
+  int b;
+  TestClass() : a(0), b(0) {}
+  TestClass& operator++();
+  TestClass(int x, int y) : a(x), b(y) {}
+};
+
----------------
flovent wrote:

I add testcase for `for (auto [k, v] : my_map);` in  [4da01f9](https://github.com/llvm/llvm-project/pull/158462/commits/4da01f9a8b1d747e5d4dd75415ff93e0723e355d), 
For the iterator case:
```
std::unordered_map::iterator it;
auto key = it->first;
auto value = it->second;
```
`->` should be `operator->` too? it's not supported because we check `MemberExpr` to `VarDecl` now and it might has side effects for `operator->`(We don't know whether it just get it's member).

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


More information about the cfe-commits mailing list