1
- // 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/
2
- // RUN: %check_clang_tidy -check-suffix=ALL - std=c++17 %s modernize-use-structured-binding %t -- -- -I %S/Inputs/use-structured-binding/
1
+ // RUN: %check_clang_tidy -check-suffix=,CPP20ORLATER -std=c++20-or-later %s modernize-use-structured-binding %t -- -- -I %S/Inputs/use-structured-binding/
2
+ // RUN: %check_clang_tidy -std=c++17 %s modernize-use-structured-binding %t -- -- -I %S/Inputs/use-structured-binding/
3
3
#include " fake_std_pair_tuple.h"
4
4
5
5
template <typename T>
@@ -16,149 +16,149 @@ struct TestClass {
16
16
void DecomposeByAssignWarnCases () {
17
17
{
18
18
auto P = getPair<int , int >();
19
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
20
- // CHECK-FIXES-ALL : auto [x, y] = getPair<int, int>();
19
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
20
+ // CHECK-FIXES: auto [x, y] = getPair<int, int>();
21
21
int x = P.first ;
22
22
int y = P.second ; // REMOVE
23
- // CHECK-FIXES-ALL : // REMOVE
23
+ // CHECK-FIXES: // REMOVE
24
24
}
25
25
26
26
{
27
27
auto P = getPair<int , int >();
28
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
29
- // CHECK-FIXES-ALL : auto [x, y] = getPair<int, int>();
28
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
29
+ // CHECK-FIXES: auto [x, y] = getPair<int, int>();
30
30
int x = P.first , y = P.second ; // REMOVE
31
- // CHECK-FIXES-ALL : // REMOVE
31
+ // CHECK-FIXES: // REMOVE
32
32
}
33
33
34
34
{
35
35
auto P = getPair<int , int >();
36
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
37
- // CHECK-FIXES-ALL : auto [x, y] = getPair<int, int>();
36
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
37
+ // CHECK-FIXES: auto [x, y] = getPair<int, int>();
38
38
int x = P.first , y = P.second ; // REMOVE
39
- // CHECK-FIXES-ALL : // REMOVE
39
+ // CHECK-FIXES: // REMOVE
40
40
int z;
41
41
}
42
42
43
43
{
44
44
auto P = getPair<int , int >();
45
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
46
- // CHECK-FIXES-ALL : auto [x, y] = getPair<int, int>();
45
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
46
+ // CHECK-FIXES: auto [x, y] = getPair<int, int>();
47
47
int x = P.first ;
48
48
auto y = P.second ; // REMOVE
49
- // CHECK-FIXES-ALL : // REMOVE
49
+ // CHECK-FIXES: // REMOVE
50
50
}
51
51
52
52
{
53
53
const auto P = getPair<int , int >();
54
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
55
- // CHECK-FIXES-ALL : const auto [x, y] = getPair<int, int>();
54
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
55
+ // CHECK-FIXES: const auto [x, y] = getPair<int, int>();
56
56
const int x = P.first ;
57
57
const auto y = P.second ; // REMOVE
58
- // CHECK-FIXES-ALL : // REMOVE
58
+ // CHECK-FIXES: // REMOVE
59
59
}
60
60
61
61
{
62
62
std::pair<int , int > otherP;
63
63
auto & P = otherP;
64
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
65
- // CHECK-FIXES-ALL : auto& [x, y] = otherP;
64
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
65
+ // CHECK-FIXES: auto& [x, y] = otherP;
66
66
int & x = P.first ;
67
67
auto & y = P.second ; // REMOVE
68
- // CHECK-FIXES-ALL : // REMOVE
68
+ // CHECK-FIXES: // REMOVE
69
69
}
70
70
71
71
{
72
72
std::pair<int , int > otherP;
73
73
const auto & P = otherP;
74
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
75
- // CHECK-FIXES-ALL : const auto& [x, y] = otherP;
74
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
75
+ // CHECK-FIXES: const auto& [x, y] = otherP;
76
76
const int & x = P.first ;
77
77
const auto & y = P.second ; // REMOVE
78
- // CHECK-FIXES-ALL : // REMOVE
78
+ // CHECK-FIXES: // REMOVE
79
79
}
80
80
81
81
{
82
82
auto P = getPair<int , int >();
83
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
84
- // CHECK-FIXES-ALL : auto [x, y] = getPair<int, int>();
83
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
84
+ // CHECK-FIXES: auto [x, y] = getPair<int, int>();
85
85
int x = P.first ;
86
86
int y = P.second ; // REMOVE
87
- // CHECK-FIXES-ALL : // REMOVE
87
+ // CHECK-FIXES: // REMOVE
88
88
89
89
auto another_p = getPair<int , int >();
90
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
91
- // CHECK-FIXES-ALL : auto [another_x, another_y] = getPair<int, int>();
90
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
91
+ // CHECK-FIXES: auto [another_x, another_y] = getPair<int, int>();
92
92
int another_x = another_p.first ;
93
93
int another_y = another_p.second ; // REMOVE
94
- // CHECK-FIXES-ALL : // REMOVE
94
+ // CHECK-FIXES: // REMOVE
95
95
}
96
96
}
97
97
98
98
void forRangeWarnCases () {
99
99
std::pair<int , int > Pairs[10 ];
100
100
for (auto P : Pairs) {
101
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
102
- // CHECK-FIXES-ALL : for (auto [x, y] : Pairs) {
101
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
102
+ // CHECK-FIXES: for (auto [x, y] : Pairs) {
103
103
int x = P.first ;
104
104
int y = P.second ; // REMOVE
105
- // CHECK-FIXES-ALL : // REMOVE
105
+ // CHECK-FIXES: // REMOVE
106
106
}
107
107
108
108
for (auto P : Pairs) {
109
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
110
- // CHECK-FIXES-ALL : for (auto [x, y] : Pairs) {
109
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
110
+ // CHECK-FIXES: for (auto [x, y] : Pairs) {
111
111
int x = P.first , y = P.second ; // REMOVE
112
- // CHECK-FIXES-ALL : // REMOVE
112
+ // CHECK-FIXES: // REMOVE
113
113
}
114
114
115
115
for (auto P : Pairs) {
116
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
117
- // CHECK-FIXES-ALL : for (auto [x, y] : Pairs) {
116
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
117
+ // CHECK-FIXES: for (auto [x, y] : Pairs) {
118
118
int x = P.first , y = P.second ; // REMOVE
119
- // CHECK-FIXES-ALL : // REMOVE
119
+ // CHECK-FIXES: // REMOVE
120
120
int z;
121
121
}
122
122
123
123
for (const auto P : Pairs) {
124
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
125
- // CHECK-FIXES-ALL : for (const auto [x, y] : Pairs) {
124
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
125
+ // CHECK-FIXES: for (const auto [x, y] : Pairs) {
126
126
const int x = P.first ;
127
127
const int y = P.second ; // REMOVE
128
- // CHECK-FIXES-ALL : // REMOVE
128
+ // CHECK-FIXES: // REMOVE
129
129
}
130
130
131
131
for (auto & P : Pairs) {
132
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
133
- // CHECK-FIXES-ALL : for (auto& [x, y] : Pairs) {
132
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
133
+ // CHECK-FIXES: for (auto& [x, y] : Pairs) {
134
134
int & x = P.first ;
135
135
int & y = P.second ; // REMOVE
136
- // CHECK-FIXES-ALL : // REMOVE
136
+ // CHECK-FIXES: // REMOVE
137
137
}
138
138
139
139
for (const auto & P : Pairs) {
140
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
141
- // CHECK-FIXES-ALL : for (const auto& [x, y] : Pairs) {
140
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
141
+ // CHECK-FIXES: for (const auto& [x, y] : Pairs) {
142
142
const int & x = P.first ;
143
143
const int & y = P.second ; // REMOVE
144
- // CHECK-FIXES-ALL : // REMOVE
144
+ // CHECK-FIXES: // REMOVE
145
145
}
146
146
147
147
std::pair<TestClass, TestClass> ClassPairs[10 ];
148
148
for (auto P : ClassPairs) {
149
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
150
- // CHECK-FIXES-ALL : for (auto [c1, c2] : ClassPairs) {
149
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
150
+ // CHECK-FIXES: for (auto [c1, c2] : ClassPairs) {
151
151
TestClass c1 = P.first ;
152
152
TestClass c2 = P.second ; // REMOVE
153
- // CHECK-FIXES-ALL : // REMOVE
153
+ // CHECK-FIXES: // REMOVE
154
154
}
155
155
156
156
for (const auto P : ClassPairs) {
157
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
158
- // CHECK-FIXES-ALL : for (const auto [c1, c2] : ClassPairs) {
157
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
158
+ // CHECK-FIXES: for (const auto [c1, c2] : ClassPairs) {
159
159
const TestClass c1 = P.first ;
160
160
const TestClass c2 = P.second ; // REMOVE
161
- // CHECK-FIXES-ALL : // REMOVE
161
+ // CHECK-FIXES: // REMOVE
162
162
}
163
163
}
164
164
@@ -200,30 +200,30 @@ void forRangeNotWarnCases() {
200
200
void stdTieWarnCases () {
201
201
int a = 0 ;
202
202
int b = 0 ; // REMOVE
203
- // CHECK-FIXES-ALL : // REMOVE
203
+ // CHECK-FIXES: // REMOVE
204
204
std::tie (a, b) = getPair<int , int >();
205
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:3: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
206
- // CHECK-FIXES-ALL : auto [a, b] = getPair<int, int>();
205
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
206
+ // CHECK-FIXES: auto [a, b] = getPair<int, int>();
207
207
208
208
int x = 0 , y = 0 ; // REMOVE
209
- // CHECK-FIXES-ALL : // REMOVE
209
+ // CHECK-FIXES: // REMOVE
210
210
std::tie (x, y) = getPair<int , int >();
211
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:3: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
212
- // CHECK-FIXES-ALL : auto [x, y] = getPair<int, int>();
211
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
212
+ // CHECK-FIXES: auto [x, y] = getPair<int, int>();
213
213
214
214
int * pa = nullptr ;
215
215
int * pb = nullptr ; // REMOVE
216
- // CHECK-FIXES-ALL : // REMOVE
216
+ // CHECK-FIXES: // REMOVE
217
217
std::tie (pa, pb) = getPair<int *, int *>();
218
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:3: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
219
- // CHECK-FIXES-ALL : auto [pa, pb] = getPair<int*, int*>();
218
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
219
+ // CHECK-FIXES: auto [pa, pb] = getPair<int*, int*>();
220
220
221
221
TestClass c1 (1 , 2 );
222
222
TestClass c2 = TestClass {3 , 4 }; // REMOVE
223
- // CHECK-FIXES-ALL : // REMOVE
223
+ // CHECK-FIXES: // REMOVE
224
224
std::tie (c1, c2) = getPair<TestClass, TestClass>();
225
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:3: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
226
- // CHECK-FIXES-ALL : auto [c1, c2] = getPair<TestClass, TestClass>();
225
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
226
+ // CHECK-FIXES: auto [c1, c2] = getPair<TestClass, TestClass>();
227
227
}
228
228
229
229
void stdTieNotWarnCases () {
@@ -413,39 +413,39 @@ struct otherPair {
413
413
void OtherPairTest () {
414
414
{
415
415
auto P = otherPair ();
416
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
417
- // CHECK-FIXES-ALL : auto [x, y] = otherPair();
416
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
417
+ // CHECK-FIXES: auto [x, y] = otherPair();
418
418
int x = P.first ;
419
419
int y = P.second ;
420
420
}
421
421
422
422
{
423
423
const auto P = otherPair ();
424
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
425
- // CHECK-FIXES-ALL : const auto [x, y] = otherPair();
424
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
425
+ // CHECK-FIXES: const auto [x, y] = otherPair();
426
426
const int x = P.first ;
427
427
const auto y = P.second ; // REMOVE
428
- // CHECK-FIXES-ALL : // REMOVE
428
+ // CHECK-FIXES: // REMOVE
429
429
}
430
430
431
431
{
432
432
otherPair otherP;
433
433
auto & P = otherP;
434
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
435
- // CHECK-FIXES-ALL : auto& [x, y] = otherP;
434
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
435
+ // CHECK-FIXES: auto& [x, y] = otherP;
436
436
int & x = P.first ;
437
437
auto & y = P.second ; // REMOVE
438
- // CHECK-FIXES-ALL : // REMOVE
438
+ // CHECK-FIXES: // REMOVE
439
439
}
440
440
441
441
{
442
442
std::pair<int , int > otherP;
443
443
const auto & P = otherP;
444
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
445
- // CHECK-FIXES-ALL : const auto& [x, y] = otherP;
444
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
445
+ // CHECK-FIXES: const auto& [x, y] = otherP;
446
446
const int & x = P.first ;
447
447
const auto & y = P.second ; // REMOVE
448
- // CHECK-FIXES-ALL : // REMOVE
448
+ // CHECK-FIXES: // REMOVE
449
449
}
450
450
}
451
451
@@ -514,20 +514,20 @@ struct ConstFieldPair {
514
514
void ConstFieldPairTests () {
515
515
{
516
516
const ConstFieldPair P = getCertainPair<ConstFieldPair>();
517
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
518
- // CHECK-FIXES-ALL : const auto [x, y] = getCertainPair<ConstFieldPair>();
517
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
518
+ // CHECK-FIXES: const auto [x, y] = getCertainPair<ConstFieldPair>();
519
519
const int x = P.first ;
520
520
const int y = P.second ; // REMOVE
521
- // CHECK-FIXES-ALL : // REMOVE
521
+ // CHECK-FIXES: // REMOVE
522
522
}
523
523
524
524
{
525
525
const ConstFieldPair& P = getCertainPair<ConstFieldPair>();
526
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
527
- // CHECK-FIXES-ALL : const auto& [x, y] = getCertainPair<ConstFieldPair>();
526
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
527
+ // CHECK-FIXES: const auto& [x, y] = getCertainPair<ConstFieldPair>();
528
528
const int & x = P.first ;
529
529
const int & y = P.second ; // REMOVE
530
- // CHECK-FIXES-ALL : // REMOVE
530
+ // CHECK-FIXES: // REMOVE
531
531
}
532
532
533
533
{
@@ -545,11 +545,11 @@ struct PointerFieldPair {
545
545
void PointerFieldPairTests () {
546
546
{
547
547
PointerFieldPair P = getCertainPair<PointerFieldPair>();
548
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
549
- // CHECK-FIXES-ALL : auto [x, y] = getCertainPair<PointerFieldPair>();
548
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
549
+ // CHECK-FIXES: auto [x, y] = getCertainPair<PointerFieldPair>();
550
550
int * x = P.first ;
551
551
int y = P.second ; // REMOVE
552
- // CHECK-FIXES-ALL : // REMOVE
552
+ // CHECK-FIXES: // REMOVE
553
553
}
554
554
555
555
{
@@ -568,11 +568,11 @@ struct ConstRefFieldPair {
568
568
void ConstRefFieldPairTests () {
569
569
{
570
570
ConstRefFieldPair P = getCertainPair<ConstRefFieldPair>();
571
- // CHECK-MESSAGES-ALL : :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
572
- // CHECK-FIXES-ALL : auto [x, y] = getCertainPair<ConstRefFieldPair>();
571
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
572
+ // CHECK-FIXES: auto [x, y] = getCertainPair<ConstRefFieldPair>();
573
573
const int & x = P.first ;
574
574
int y = P.second ; // REMOVE
575
- // CHECK-FIXES-ALL : // REMOVE
575
+ // CHECK-FIXES: // REMOVE
576
576
}
577
577
578
578
{
0 commit comments