Skip to content

Commit 4da01f9

Browse files
committed
[NFC][TEST] Add testcase for std::unordered_map
1 parent 8d3054c commit 4da01f9

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/use-structured-binding/fake_std_pair_tuple.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ namespace std {
2020
tuple<Args...> tie(Args&... args) {
2121
return tuple<Args...>(args...);
2222
}
23+
24+
template <typename Key, typename Value>
25+
class unordered_map {
26+
public:
27+
using value_type = pair<Key, Value>;
28+
29+
class iterator {
30+
public:
31+
iterator& operator++();
32+
bool operator!=(const iterator &other);
33+
const value_type &operator*() const;
34+
value_type operator*();
35+
const value_type* operator->() const;
36+
};
37+
38+
iterator begin() const;
39+
iterator end() const;
40+
};
2341
}
2442

2543
template<typename T1, typename T2>

clang-tools-extra/test/clang-tidy/checkers/modernize/use-structured-binding.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,3 +651,15 @@ void IgnoreDirectInit() {
651651
int y = P.second;
652652
}
653653
}
654+
655+
void StdMapTestCases() {
656+
for (auto p : std::unordered_map<int, int>()) {
657+
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
658+
// CHECK-FIXES: for (auto [x, y] : std::unordered_map<int, int>()) {
659+
// CHECK-NEXT: // REMOVE
660+
int x = p.first;
661+
int y = p.second; // REMOVE
662+
// CHECK-FIXES: // REMOVE
663+
}
664+
}
665+

0 commit comments

Comments
 (0)