Skip to content

Commit 7b7ba72

Browse files
committed
[NFC] Add more tests for custom pair type
1 parent 0607998 commit 7b7ba72

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,61 @@ void OtherPairTest() {
402402
int x = P.first;
403403
int y = P.second;
404404
}
405+
406+
{
407+
const auto P = otherPair();
408+
// CHECK-MESSAGES-ALL: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
409+
// CHECK-FIXES-ALL: const auto [x, y] = otherPair();
410+
const int x = P.first;
411+
const auto y = P.second; // REMOVE
412+
// CHECK-FIXES-ALL: // REMOVE
413+
}
414+
415+
{
416+
otherPair otherP;
417+
auto& P = otherP;
418+
// CHECK-MESSAGES-ALL: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
419+
// CHECK-FIXES-ALL: auto& [x, y] = otherP;
420+
int& x = P.first;
421+
auto& y = P.second; // REMOVE
422+
// CHECK-FIXES-ALL: // REMOVE
423+
}
424+
425+
{
426+
std::pair<int, int> otherP;
427+
const auto& P = otherP;
428+
// CHECK-MESSAGES-ALL: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
429+
// CHECK-FIXES-ALL: const auto& [x, y] = otherP;
430+
const int& x = P.first;
431+
const auto& y = P.second; // REMOVE
432+
// CHECK-FIXES-ALL: // REMOVE
433+
}
434+
}
435+
436+
void OtherPairNotWarnCases() {
437+
{
438+
auto P = otherPair();
439+
const int x = P.first;
440+
int y = P.second;
441+
}
442+
443+
{
444+
auto P = otherPair();
445+
volatile int x = P.first;
446+
int y = P.second;
447+
}
448+
449+
{
450+
auto P = otherPair();
451+
int x = P.first;
452+
[[maybe_unused]] int y = P.second;
453+
}
454+
455+
{
456+
static auto P = getPair<int, int>();
457+
int x = P.first;
458+
int y = P.second;
459+
}
405460
}
406461

407462
struct otherNonPair1 {

0 commit comments

Comments
 (0)