File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -402,6 +402,61 @@ void OtherPairTest() {
402
402
int x = P.first ;
403
403
int y = P.second ;
404
404
}
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
+ }
405
460
}
406
461
407
462
struct otherNonPair1 {
You can’t perform that action at this time.
0 commit comments