@@ -503,3 +503,101 @@ void OtherNonPairTest() {
503
503
int y = P.second ;
504
504
}
505
505
}
506
+
507
+ template <typename PairType>
508
+ PairType getCertainPair ();
509
+
510
+ struct ConstFieldPair {
511
+ const int first;
512
+ int second;
513
+ };
514
+
515
+ void ConstFieldPairTests () {
516
+ {
517
+ const ConstFieldPair P = getCertainPair<ConstFieldPair>();
518
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
519
+ // CHECK-FIXES-ALL: const auto [x, y] = getCertainPair<ConstFieldPair>();
520
+ const int x = P.first ;
521
+ const int y = P.second ; // REMOVE
522
+ // CHECK-FIXES-ALL: // REMOVE
523
+ }
524
+
525
+ {
526
+ const ConstFieldPair& P = getCertainPair<ConstFieldPair>();
527
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
528
+ // CHECK-FIXES-ALL: const auto& [x, y] = getCertainPair<ConstFieldPair>();
529
+ const int & x = P.first ;
530
+ const int & y = P.second ; // REMOVE
531
+ // CHECK-FIXES-ALL: // REMOVE
532
+ }
533
+
534
+ {
535
+ ConstFieldPair P = getCertainPair<ConstFieldPair>(); // no warning
536
+ int x = P.first ;
537
+ int y = P.second ;
538
+ }
539
+ }
540
+
541
+ struct PointerFieldPair {
542
+ int * first;
543
+ int second;
544
+ };
545
+
546
+ void PointerFieldPairTests () {
547
+ {
548
+ PointerFieldPair P = getCertainPair<PointerFieldPair>();
549
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
550
+ // CHECK-FIXES-ALL: auto [x, y] = getCertainPair<PointerFieldPair>();
551
+ int * x = P.first ;
552
+ int y = P.second ; // REMOVE
553
+ // CHECK-FIXES-ALL: // REMOVE
554
+ }
555
+
556
+ {
557
+ PointerFieldPair P = getCertainPair<PointerFieldPair>(); // no warning
558
+ const int * x = P.first ;
559
+ int y = P.second ;
560
+ }
561
+ }
562
+
563
+ struct ConstRefFieldPair {
564
+ const int & first;
565
+ int second;
566
+ ConstRefFieldPair (int & f, int s) : first(f), second(s) {}
567
+ };
568
+
569
+ void ConstRefFieldPairTests () {
570
+ {
571
+ ConstRefFieldPair P = getCertainPair<ConstRefFieldPair>();
572
+ // CHECK-MESSAGES-ALL: :[[@LINE-1]]:5: warning: use a structured binding to decompose a pair [modernize-use-structured-binding]
573
+ // CHECK-FIXES-ALL: auto [x, y] = getCertainPair<ConstRefFieldPair>();
574
+ const int & x = P.first ;
575
+ int y = P.second ; // REMOVE
576
+ // CHECK-FIXES-ALL: // REMOVE
577
+ }
578
+
579
+ {
580
+ ConstRefFieldPair P = getCertainPair<ConstRefFieldPair>();; // no warning
581
+ int x = P.first ;
582
+ int y = P.second ;
583
+ }
584
+ }
585
+
586
+ struct StaticFieldPair {
587
+ static int first;
588
+ int second;
589
+ };
590
+
591
+ void StaticFieldPairTests () {
592
+ {
593
+ StaticFieldPair P; // Should not warn
594
+ int x = P.first ;
595
+ int y = P.second ;
596
+ }
597
+
598
+ {
599
+ StaticFieldPair P; // Should not warn
600
+ static int x = P.first ;
601
+ int y = P.second ;
602
+ }
603
+ }
0 commit comments