modernize-loop-convert-extra.cpp 33.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
// RUN: %check_clang_tidy %s modernize-loop-convert %t -- -- -I %S/Inputs/modernize-loop-convert

#include "structures.h"

namespace Dependency {

void f() {
  const int N = 6;
  const int M = 8;
  int Arr[N][M];

  for (int I = 0; I < N; ++I) {
    int A = 0;
    int B = Arr[I][A];
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & I : Arr)
  // CHECK-FIXES-NEXT: int A = 0;
  // CHECK-FIXES-NEXT: int B = I[A];

  for (int J = 0; J < M; ++J) {
    int A = 0;
    int B = Arr[A][J];
  }
}

} // namespace Dependency

namespace NamingAlias {

const int N = 10;

Val Arr[N];
dependent<Val> V;
dependent<Val> *Pv;
Val &func(Val &);
void sideEffect(int);

void aliasing() {
  // If the loop container is only used for a declaration of a temporary
  // variable to hold each element, we can name the new variable for the
  // converted range-based loop as the temporary variable's name.

  // In the following case, "T" is used as a temporary variable to hold each
  // element, and thus we consider the name "T" aliased to the loop.
  // The extra blank braces are left as a placeholder for after the variable
  // declaration is deleted.
  for (int I = 0; I < N; ++I) {
    Val &T = Arr[I];
    {}
    int Y = T.X;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & T : Arr)
  // CHECK-FIXES-NOT: Val &{{[a-z_]+}} =
  // CHECK-FIXES-NEXT: {}
  // CHECK-FIXES-NEXT: int Y = T.X;

  // The container was not only used to initialize a temporary loop variable for
  // the container's elements, so we do not alias the new loop variable.
  for (int I = 0; I < N; ++I) {
    Val &T = Arr[I];
    int Y = T.X;
    int Z = Arr[I].X + T.X;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & I : Arr)
  // CHECK-FIXES-NEXT: Val &T = I;
  // CHECK-FIXES-NEXT: int Y = T.X;
  // CHECK-FIXES-NEXT: int Z = I.X + T.X;

  for (int I = 0; I < N; ++I) {
    Val T = Arr[I];
    int Y = T.X;
    int Z = Arr[I].X + T.X;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & I : Arr)
  // CHECK-FIXES-NEXT: Val T = I;
  // CHECK-FIXES-NEXT: int Y = T.X;
  // CHECK-FIXES-NEXT: int Z = I.X + T.X;

  // The same for pseudo-arrays like std::vector<T> (or here dependent<Val>)
  // which provide a subscript operator[].
  for (int I = 0; I < V.size(); ++I) {
    Val &T = V[I];
    {}
    int Y = T.X;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & T : V)
  // CHECK-FIXES-NEXT: {}
  // CHECK-FIXES-NEXT: int Y = T.X;

  // The same with a call to at()
  for (int I = 0; I < Pv->size(); ++I) {
    Val &T = Pv->at(I);
    {}
    int Y = T.X;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & T : *Pv)
  // CHECK-FIXES-NEXT: {}
  // CHECK-FIXES-NEXT: int Y = T.X;

  for (int I = 0; I < N; ++I) {
    Val &T = func(Arr[I]);
    int Y = T.X;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & I : Arr)
  // CHECK-FIXES-NEXT: Val &T = func(I);
  // CHECK-FIXES-NEXT: int Y = T.X;

  int IntArr[N];
  for (unsigned I = 0; I < N; ++I) {
    if (int Alias = IntArr[I]) {
      sideEffect(Alias);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Alias : IntArr)
  // CHECK-FIXES-NEXT: if (Alias)

  for (unsigned I = 0; I < N; ++I) {
    while (int Alias = IntArr[I]) {
      sideEffect(Alias);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Alias : IntArr)
  // CHECK-FIXES-NEXT: while (Alias)

  for (unsigned I = 0; I < N; ++I) {
    switch (int Alias = IntArr[I]) {
    default:
      sideEffect(Alias);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Alias : IntArr)
  // CHECK-FIXES-NEXT: switch (Alias)

  for (unsigned I = 0; I < N; ++I) {
    for (int Alias = IntArr[I]; Alias < N; ++Alias) {
      sideEffect(Alias);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Alias : IntArr)
  // CHECK-FIXES-NEXT: for (; Alias < N; ++Alias)

  for (unsigned I = 0; I < N; ++I) {
    for (unsigned J = 0; int Alias = IntArr[I]; ++J) {
      sideEffect(Alias);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Alias : IntArr)
  // CHECK-FIXES-NEXT: for (unsigned J = 0; Alias; ++J)

  struct IntRef { IntRef(); IntRef(const int& i); operator int*(); };
  for (int I = 0; I < N; ++I) {
    IntRef Int(IntArr[I]);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int I : IntArr)
  // CHECK-FIXES-NEXT: IntRef Int(I);

  int *PtrArr[N];
  for (unsigned I = 0; I < N; ++I) {
    const int* const P = PtrArr[I];
    printf("%d\n", *P);
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto P : PtrArr)
  // CHECK-FIXES-NEXT: printf("%d\n", *P);

  IntRef Refs[N];
  for (unsigned I = 0; I < N; ++I) {
    int *P = Refs[I];
    printf("%d\n", *P);
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & Ref : Refs)
  // CHECK-FIXES-NEXT: int *P = Ref;
  // CHECK-FIXES-NEXT: printf("%d\n", *P);

  // Ensure that removing the alias doesn't leave empty lines behind.
  for (int I = 0; I < N; ++I) {
    auto &X = IntArr[I];
    X = 0;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & X : IntArr) {
  // CHECK-FIXES-NEXT: {{^    X = 0;$}}
  // CHECK-FIXES-NEXT: {{^  }$}}
}

void refs_and_vals() {
  // The following tests check that the transform correctly preserves the
  // reference or value qualifiers of the aliased variable. That is, if the
  // variable was declared as a value, the loop variable will be declared as a
  // value and vice versa for references.

  S Ss;
  const S S_const = Ss;

  for (S::const_iterator It = S_const.begin(); It != S_const.end(); ++It) {
    MutableVal Alias = *It;
    {}
    Alias.X = 0;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto Alias : S_const)
  // CHECK-FIXES-NOT: MutableVal {{[a-z_]+}} =
  // CHECK-FIXES-NEXT: {}
  // CHECK-FIXES-NEXT: Alias.X = 0;

  for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) {
    MutableVal Alias = *It;
    {}
    Alias.X = 0;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto Alias : Ss)
  // CHECK-FIXES-NOT: MutableVal {{[a-z_]+}} =
  // CHECK-FIXES-NEXT: {}
  // CHECK-FIXES-NEXT: Alias.X = 0;

  for (S::iterator It = Ss.begin(), E = Ss.end(); It != E; ++It) {
    MutableVal &Alias = *It;
    {}
    Alias.X = 0;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & Alias : Ss)
  // CHECK-FIXES-NOT: MutableVal &{{[a-z_]+}} =
  // CHECK-FIXES-NEXT: {}
  // CHECK-FIXES-NEXT: Alias.X = 0;

  dependent<int> Dep, Other;
  for (dependent<int>::iterator It = Dep.begin(), E = Dep.end(); It != E; ++It) {
    printf("%d\n", *It);
    const int& Idx = Other[0];
    unsigned Othersize = Other.size();
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & It : Dep)
  // CHECK-FIXES-NEXT: printf("%d\n", It);
  // CHECK-FIXES-NEXT: const int& Idx = Other[0];
  // CHECK-FIXES-NEXT: unsigned Othersize = Other.size();

  for (int i = 0; i <  Other.size(); ++i) {
    Other.at(i);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & i : Other)
  // CHECK-FIXES: i;

  for (int I = 0, E = Dep.size(); I != E; ++I) {
    int Idx = Other.at(I);
    Other.at(I, I);  // Should not trigger assert failure.
  }
}

struct MemberNaming {
  const static int N = 10;
  int Ints[N], Ints_[N];
  dependent<int> DInts;
  void loops() {
    for (int I = 0; I < N; ++I) {
      printf("%d\n", Ints[I]);
    }
    // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
    // CHECK-FIXES: for (int Int : Ints)
    // CHECK-FIXES-NEXT: printf("%d\n", Int);

    for (int I = 0; I < N; ++I) {
      printf("%d\n", Ints_[I]);
    }
    // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
    // CHECK-FIXES: for (int Int : Ints_)
    // CHECK-FIXES-NEXT: printf("%d\n", Int);

    for (int I = 0; I < DInts.size(); ++I) {
      printf("%d\n", DInts[I]);
    }
    // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: use range-based for loop instead
    // CHECK-FIXES: for (int DInt : DInts)
    // CHECK-FIXES-NEXT: printf("%d\n", DInt);
  }

  void outOfLine();
};
void MemberNaming::outOfLine() {
  for (int I = 0; I < N; ++I) {
    printf("%d\n", Ints[I]);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Int : Ints)
  // CHECK-FIXES-NEXT: printf("%d\n", Int);

  for (int I = 0; I < N; ++I) {
    printf("%d\n", Ints_[I]);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Int : Ints_)
  // CHECK-FIXES-NEXT: printf("%d\n", Int);
}

} // namespace NamingAlias

namespace NamingConlict {

#define MAX(a, b) (a > b) ? a : b
#define DEF 5

const int N = 10;
int Nums[N];
int Sum = 0;

namespace ns {
struct St {
  int X;
};
}

void sameNames() {
  int Num = 0;
  for (int I = 0; I < N; ++I) {
    printf("Fibonacci number is %d\n", Nums[I]);
    Sum += Nums[I] + 2 + Num;
    (void)Nums[I];
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & I : Nums)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
  // CHECK-FIXES-NEXT: Sum += I + 2 + Num;
  // CHECK-FIXES-NEXT: (void)I;

  int Elem = 0;
  for (int I = 0; I < N; ++I) {
    printf("Fibonacci number is %d\n", Nums[I]);
    Sum += Nums[I] + 2 + Num + Elem;
    (void)Nums[I];
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & I : Nums)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", I);
  // CHECK-FIXES-NEXT: Sum += I + 2 + Num + Elem;
  // CHECK-FIXES-NEXT: (void)I;
}

void oldIndexConflict() {
  for (int Num = 0; Num < N; ++Num) {
    printf("Num: %d\n", Nums[Num]);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int Num : Nums)
  // CHECK-FIXES-NEXT: printf("Num: %d\n", Num);

  S Things;
  for (S::iterator Thing = Things.begin(), End = Things.end(); Thing != End; ++Thing) {
    printf("Thing: %d %d\n", Thing->X, (*Thing).X);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & Thing : Things)
  // CHECK-FIXES-NEXT: printf("Thing: %d %d\n", Thing.X, Thing.X);
}

void macroConflict() {
  S MAXs;
  for (S::iterator It = MAXs.begin(), E = MAXs.end(); It != E; ++It) {
    printf("s has value %d\n", (*It).X);
    printf("Max of 3 and 5: %d\n", MAX(3, 5));
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & It : MAXs)
  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
  // CHECK-FIXES-NEXT: printf("Max of 3 and 5: %d\n", MAX(3, 5));

  for (S::const_iterator It = MAXs.begin(), E = MAXs.end(); It != E; ++It) {
    printf("s has value %d\n", (*It).X);
    printf("Max of 3 and 5: %d\n", MAX(3, 5));
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto It : MAXs)
  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);
  // CHECK-FIXES-NEXT: printf("Max of 3 and 5: %d\n", MAX(3, 5));

  T DEFs;
  for (T::iterator It = DEFs.begin(), E = DEFs.end(); It != E; ++It) {
    if (*It == DEF) {
      printf("I found %d\n", *It);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & It : DEFs)
  // CHECK-FIXES-NEXT: if (It == DEF)
  // CHECK-FIXES-NEXT: printf("I found %d\n", It);
}

void keywordConflict() {
  T ints;
  for (T::iterator It = ints.begin(), E = ints.end(); It != E; ++It) {
    *It = 5;
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & It : ints)
  // CHECK-FIXES-NEXT: It = 5;

  U __FUNCTION__s;
  for (U::iterator It = __FUNCTION__s.begin(), E = __FUNCTION__s.end();
       It != E; ++It) {
    int __FUNCTION__s_It = (*It).X + 2;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & It : __FUNCTION__s)
  // CHECK-FIXES-NEXT: int __FUNCTION__s_It = It.X + 2;
}

void typeConflict() {
  T Vals;
  // Using the name "Val", although it is the name of an existing struct, is
  // safe in this loop since it will only exist within this scope.
  for (T::iterator It = Vals.begin(), E = Vals.end(); It != E; ++It)
    (void) *It;
  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & Val : Vals)

  // We cannot use the name "Val" in this loop since there is a reference to
  // it in the body of the loop.
  for (T::iterator It = Vals.begin(), E = Vals.end(); It != E; ++It) {
    *It = sizeof(Val);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & It : Vals)
  // CHECK-FIXES-NEXT: It = sizeof(Val);

  typedef struct Val TD;
  U TDs;
  // Naming the variable "TD" within this loop is safe because the typedef
  // was never used within the loop.
  for (U::iterator It = TDs.begin(), E = TDs.end(); It != E; ++It)
    (void) *It;
  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & TD : TDs)

  // "TD" cannot be used in this loop since the typedef is being used.
  for (U::iterator It = TDs.begin(), E = TDs.end(); It != E; ++It) {
    TD V;
    V.X = 5;
    (void) *It;
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & It : TDs)
  // CHECK-FIXES-NEXT: TD V;
  // CHECK-FIXES-NEXT: V.X = 5;

  using ns::St;
  T Sts;
  for (T::iterator It = Sts.begin(), E = Sts.end(); It != E; ++It) {
    *It = sizeof(St);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & It : Sts)
  // CHECK-FIXES-NEXT: It = sizeof(St);
}

} // namespace NamingConflict

namespace FreeBeginEnd {

// FIXME: Loop Convert should detect free begin()/end() functions.

struct MyArray {
  unsigned size();
};

template <typename T>
struct MyContainer {
};

int *begin(const MyArray &Arr);
int *end(const MyArray &Arr);

template <typename T>
T *begin(const MyContainer<T> &C);
template <typename T>
T *end(const MyContainer<T> &C);

// The Loop Convert Transform doesn't detect free functions begin()/end() and
// so fails to transform these cases which it should.
void f() {
  MyArray Arr;
  for (unsigned I = 0, E = Arr.size(); I < E; ++I) {
  }

  MyContainer<int> C;
  for (int *I = begin(C), *E = end(C); I != E; ++I) {
  }
}

} // namespace FreeBeginEnd

namespace Nesting {

void g(S::iterator It);
void const_g(S::const_iterator It);
class Foo {
 public:
  void g(S::iterator It);
  void const_g(S::const_iterator It);
};

void f() {
  const int N = 10;
  const int M = 15;
  Val Arr[N];
  for (int I = 0; I < N; ++I) {
    for (int J = 0; J < N; ++J) {
      int K = Arr[I].X + Arr[J].X;
      // The repeat is there to allow FileCheck to make sure the two variable
      // names aren't the same.
      int L = Arr[I].X + Arr[J].X;
    }
  }
  // CHECK-MESSAGES: :[[@LINE-8]]:3: warning: use range-based for loop instead
  // CHECK-MESSAGES: :[[@LINE-8]]:5: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & I : Arr)
  // CHECK-FIXES-NEXT: for (auto & J : Arr)
  // CHECK-FIXES-NEXT: int K = I.X + J.X;
  // CHECK-FIXES-NOT: int L = I.X + I.X;

  // The inner loop is also convertible, but doesn't need to be converted
  // immediately. FIXME: update this test when that changes.
  Val Nest[N][M];
  for (int I = 0; I < N; ++I) {
    for (int J = 0; J < M; ++J) {
      printf("Got item %d", Nest[I][J].X);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & I : Nest)
  // CHECK-FIXES-NEXT: for (int J = 0; J < M; ++J)
  // CHECK-FIXES-NEXT: printf("Got item %d", I[J].X);

  // Note that the order of M and N are switched for this test.
  for (int J = 0; J < M; ++J) {
    for (int I = 0; I < N; ++I) {
      printf("Got item %d", Nest[I][J].X);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop instead
  // CHECK-FIXES-NOT: for (auto & {{[a-zA-Z_]+}} : Nest[I])
  // CHECK-FIXES: for (int J = 0; J < M; ++J)
  // CHECK-FIXES-NEXT: for (auto & I : Nest)
  // CHECK-FIXES-NEXT: printf("Got item %d", I[J].X);

  // The inner loop is also convertible.
  Nested<T> NestT;
  for (Nested<T>::iterator I = NestT.begin(), E = NestT.end(); I != E; ++I) {
    for (T::iterator TI = (*I).begin(), TE = (*I).end(); TI != TE; ++TI) {
      printf("%d", *TI);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & I : NestT)
  // CHECK-FIXES-NEXT: for (T::iterator TI = I.begin(), TE = I.end(); TI != TE; ++TI)
  // CHECK-FIXES-NEXT: printf("%d", *TI);

  // The inner loop is also convertible.
  Nested<S> NestS;
  for (Nested<S>::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
    for (S::const_iterator SI = (*I).begin(), SE = (*I).end(); SI != SE; ++SI) {
      printf("%d", *SI);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto I : NestS)
  // CHECK-FIXES-NEXT: for (S::const_iterator SI = I.begin(), SE = I.end(); SI != SE; ++SI)
  // CHECK-FIXES-NEXT: printf("%d", *SI);

  for (Nested<S>::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
    const S &Ss = *I;
    for (S::const_iterator SI = Ss.begin(), SE = Ss.end(); SI != SE; ++SI) {
      printf("%d", *SI);
      const_g(SI);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto Ss : NestS)

  for (Nested<S>::iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
    S &Ss = *I;
    for (S::iterator SI = Ss.begin(), SE = Ss.end(); SI != SE; ++SI) {
      printf("%d", *SI);
      g(SI);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & Ss : NestS)

  Foo foo;
  for (Nested<S>::const_iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
    const S &Ss = *I;
    for (S::const_iterator SI = Ss.begin(), SE = Ss.end(); SI != SE; ++SI) {
      printf("%d", *SI);
      foo.const_g(SI);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto Ss : NestS)

  for (Nested<S>::iterator I = NestS.begin(), E = NestS.end(); I != E; ++I) {
    S &Ss = *I;
    for (S::iterator SI = Ss.begin(), SE = Ss.end(); SI != SE; ++SI) {
      printf("%d", *SI);
      foo.g(SI);
    }
  }
  // CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & Ss : NestS)

}

} // namespace Nesting

namespace SingleIterator {

void complexContainer() {
  X Exes[5];
  int Index = 0;

  for (S::iterator I = Exes[Index].getS().begin(), E = Exes[Index].getS().end(); I != E; ++I) {
    MutableVal K = *I;
    MutableVal J = *I;
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & I : Exes[Index].getS())
  // CHECK-FIXES-NEXT: MutableVal K = I;
  // CHECK-FIXES-NEXT: MutableVal J = I;
}

void f() {
  /// begin()/end() - based for loops here:
  T Tt;
  for (T::iterator It = Tt.begin(); It != Tt.end(); ++It) {
    printf("I found %d\n", *It);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & It : Tt)
  // CHECK-FIXES-NEXT: printf("I found %d\n", It);

  T *Pt;
  for (T::iterator It = Pt->begin(); It != Pt->end(); ++It) {
    printf("I found %d\n", *It);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & It : *Pt)
  // CHECK-FIXES-NEXT: printf("I found %d\n", It);

  S Ss;
  for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) {
    printf("s has value %d\n", (*It).X);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & It : Ss)
  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);

  S *Ps;
  for (S::iterator It = Ps->begin(); It != Ps->end(); ++It) {
    printf("s has value %d\n", (*It).X);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & P : *Ps)
  // CHECK-FIXES-NEXT: printf("s has value %d\n", P.X);

  for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) {
    printf("s has value %d\n", It->X);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & It : Ss)
  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);

  for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) {
    It->X = 3;
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & It : Ss)
  // CHECK-FIXES-NEXT: It.X = 3;

  for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) {
    (*It).X = 3;
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & It : Ss)
  // CHECK-FIXES-NEXT: It.X = 3;

  for (S::iterator It = Ss.begin(); It != Ss.end(); ++It) {
    It->nonConstFun(4, 5);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & It : Ss)
  // CHECK-FIXES-NEXT: It.nonConstFun(4, 5);

  U Uu;
  for (U::iterator It = Uu.begin(); It != Uu.end(); ++It) {
    printf("s has value %d\n", It->X);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & It : Uu)
  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);

  for (U::iterator It = Uu.begin(); It != Uu.end(); ++It) {
    printf("s has value %d\n", (*It).X);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & It : Uu)
  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);

  U::iterator A;
  for (U::iterator I = Uu.begin(); I != Uu.end(); ++I)
    int K = A->X + I->X;
  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & I : Uu)
  // CHECK-FIXES-NEXT: int K = A->X + I.X;

  dependent<int> V;
  for (dependent<int>::iterator It = V.begin();
       It != V.end(); ++It) {
    printf("Fibonacci number is %d\n", *It);
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & It : V)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It);

  for (dependent<int>::iterator It(V.begin());
       It != V.end(); ++It) {
    printf("Fibonacci number is %d\n", *It);
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & It : V)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It);

  doublyDependent<int, int> intmap;
  for (doublyDependent<int, int>::iterator It = intmap.begin();
       It != intmap.end(); ++It) {
    printf("intmap[%d] = %d", It->first, It->second);
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & It : intmap)
  // CHECK-FIXES-NEXT: printf("intmap[%d] = %d", It.first, It.second);
}

void different_type() {
  // Tests to verify the proper use of auto where the init variable type and the
  // initializer type differ or are mostly the same except for const qualifiers.

  // Ss.begin() returns a type 'iterator' which is just a non-const pointer and
  // differs from const_iterator only on the const qualification.
  S Ss;
  for (S::const_iterator It = Ss.begin(); It != Ss.end(); ++It) {
    printf("s has value %d\n", (*It).X);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto It : Ss)
  // CHECK-FIXES-NEXT: printf("s has value %d\n", It.X);

  S *Ps;
  for (S::const_iterator It = Ps->begin(); It != Ps->end(); ++It) {
    printf("s has value %d\n", (*It).X);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto P : *Ps)
  // CHECK-FIXES-NEXT: printf("s has value %d\n", P.X);

  dependent<int> V;
  for (dependent<int>::const_iterator It = V.begin(); It != V.end(); ++It) {
    printf("Fibonacci number is %d\n", *It);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int It : V)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It);

  for (dependent<int>::const_iterator It(V.begin()); It != V.end(); ++It) {
    printf("Fibonacci number is %d\n", *It);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int It : V)
  // CHECK-FIXES-NEXT: printf("Fibonacci number is %d\n", It);
}

} // namespace SingleIterator


namespace Macros {

#define TWO_PARAM(x, y) if (x == y) {}
#define THREE_PARAM(x, y, z) if (x == y) {z;}

const int N = 10;
int Arr[N];

void messing_with_macros() {
  for (int I = 0; I < N; ++I) {
    printf("Value: %d\n", Arr[I]);
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int I : Arr)
  // CHECK-FIXES-NEXT:  printf("Value: %d\n", I);

  for (int I = 0; I < N; ++I) {
    printf("Value: %d\n", CONT Arr[I]);
  }

  // Multiple macro arguments.
  for (int I = 0; I < N; ++I) {
    TWO_PARAM(Arr[I], Arr[I]);
    THREE_PARAM(Arr[I], Arr[I], Arr[I]);
  }
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & I : Arr)
  // CHECK-FIXES-NEXT: TWO_PARAM(I, I);
  // CHECK-FIXES-NEXT: THREE_PARAM(I, I, I);
}

} // namespace Macros

namespace Templates {

template <class Container>
void set_union(Container &container) {
  for (typename Container::const_iterator SI = container.begin(),
       SE = container.end(); SI != SE; ++SI) {
    (void) *SI;
  }

  S Ss;
  for (S::iterator SI = Ss.begin(), SE = Ss.end(); SI != SE; ++SI)
    (void) *SI;
  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (auto & SI : Ss)
}

void template_instantiation() {
  S Ss;
  set_union(Ss);
}

} // namespace Templates

namespace Lambdas {

void capturesIndex() {
  const int N = 10;
  int Arr[N];
  // FIXME: the next four loops could be convertible, if the capture list is
  // also changed.

  for (int I = 0; I < N; ++I)
    auto F1 = [Arr, I]() { int R1 = Arr[I] + 1; };
  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int I : Arr)
  // CHECK-FIXES-NEXT: auto F1 = [Arr, &I]() { int R1 = I + 1; };

  for (int I = 0; I < N; ++I)
    auto F2 = [Arr, &I]() { int R2 = Arr[I] + 3; };
  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int I : Arr)
  // CHECK-FIXES-NEXT: auto F2 = [Arr, &I]() { int R2 = I + 3; };

  // FIXME: alias don't work if the index is captured.
  // Alias declared inside lambda (by value).
  for (int I = 0; I < N; ++I)
    auto F3 = [&Arr, I]() { int R3 = Arr[I]; };
  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int I : Arr)
  // CHECK-FIXES-NEXT: auto F3 = [&Arr, &I]() { int R3 = I; };


  for (int I = 0; I < N; ++I)
    auto F4 = [&Arr, &I]() { int R4 = Arr[I]; };
  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int I : Arr)
  // CHECK-FIXES-NEXT: auto F4 = [&Arr, &I]() { int R4 = I; };

  // Alias declared inside lambda (by reference).
  for (int I = 0; I < N; ++I)
    auto F5 = [&Arr, I]() { int &R5 = Arr[I]; };
  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & I : Arr)
  // CHECK-FIXES-NEXT: auto F5 = [&Arr, &I]() { int &R5 = I; };


  for (int I = 0; I < N; ++I)
    auto F6 = [&Arr, &I]() { int &R6 = Arr[I]; };
  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & I : Arr)
  // CHECK-FIXES-NEXT: auto F6 = [&Arr, &I]() { int &R6 = I; };

  for (int I = 0; I < N; ++I) {
    auto F = [Arr, I](int k) {
      printf("%d\n", Arr[I] + k);
    };
    F(Arr[I]);
  }
  // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int I : Arr)
  // CHECK-FIXES-NEXT: auto F = [Arr, &I](int k)
  // CHECK-FIXES-NEXT: printf("%d\n", I + k);
  // CHECK-FIXES: F(I);
}

void implicitCapture() {
  const int N = 10;
  int Arr[N];
  // Index is used, not convertible.
  for (int I = 0; I < N; ++I) {
    auto G1 = [&]() {
      int R = Arr[I];
      int J = I;
    };
  }

  for (int I = 0; I < N; ++I) {
    auto G2 = [=]() {
      int R = Arr[I];
      int J = I;
    };
  }

  // Convertible.
  for (int I = 0; I < N; ++I) {
    auto G3 = [&]() {
      int R3 = Arr[I];
      int J3 = Arr[I] + R3;
    };
  }
  // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int I : Arr)
  // CHECK-FIXES-NEXT: auto G3 = [&]()
  // CHECK-FIXES-NEXT: int R3 = I;
  // CHECK-FIXES-NEXT: int J3 = I + R3;

  for (int I = 0; I < N; ++I) {
    auto G4 = [=]() {
      int R4 = Arr[I] + 5;
    };
  }
  // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int I : Arr)
  // CHECK-FIXES-NEXT: auto G4 = [=]()
  // CHECK-FIXES-NEXT: int R4 = I + 5;

  // Alias by value.
  for (int I = 0; I < N; ++I) {
    auto G5 = [&]() {
      int R5 = Arr[I];
      int J5 = 8 + R5;
    };
  }
  // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int R5 : Arr)
  // CHECK-FIXES-NEXT: auto G5 = [&]()
  // CHECK-FIXES-NEXT: int J5 = 8 + R5;

  // Alias by reference.
  for (int I = 0; I < N; ++I) {
    auto G6 = [&]() {
      int &R6 = Arr[I];
      int J6 = -1 + R6;
    };
  }
  // CHECK-MESSAGES: :[[@LINE-6]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & R6 : Arr)
  // CHECK-FIXES-NEXT: auto G6 = [&]()
  // CHECK-FIXES-NEXT: int J6 = -1 + R6;
}

void iterators() {
  dependent<int> Dep;

  for (dependent<int>::iterator I = Dep.begin(), E = Dep.end(); I != E; ++I)
    auto H1 = [&I]() { int R = *I; };
  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & I : Dep)
  // CHECK-FIXES-NEXT: auto H1 = [&I]() { int R = I; };

  for (dependent<int>::iterator I = Dep.begin(), E = Dep.end(); I != E; ++I)
    auto H2 = [&]() { int R = *I + 2; };
  // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int & I : Dep)
  // CHECK-FIXES-NEXT: auto H2 = [&]() { int R = I + 2; };

  for (dependent<int>::const_iterator I = Dep.begin(), E = Dep.end();
       I != E; ++I)
    auto H3 = [I]() { int R = *I; };
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int I : Dep)
  // CHECK-FIXES-NEXT: auto H3 = [&I]() { int R = I; };

  for (dependent<int>::const_iterator I = Dep.begin(), E = Dep.end();
       I != E; ++I)
    auto H4 = [&]() { int R = *I + 1; };
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int I : Dep)
  // CHECK-FIXES-NEXT: auto H4 = [&]() { int R = I + 1; };

  for (dependent<int>::const_iterator I = Dep.begin(), E = Dep.end();
       I != E; ++I)
    auto H5 = [=]() { int R = *I; };
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int R : Dep)
  // CHECK-FIXES-NEXT: auto H5 = [=]() { };
}

void captureByValue() {
  // When the index is captured by value, we should replace this by a capture
  // by reference. This avoids extra copies.
  // FIXME: this could change semantics on array or pseudoarray loops if the
  // container is captured by copy.
  const int N = 10;
  int Arr[N];
  dependent<int> Dep;

  for (int I = 0; I < N; ++I) {
    auto C1 = [&Arr, I]() { if (Arr[I] == 1); };
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int I : Arr)
  // CHECK-FIXES-NEXT: auto C1 = [&Arr, &I]() { if (I == 1); };

  for (unsigned I = 0; I < Dep.size(); ++I) {
    auto C2 = [&Dep, I]() { if (Dep[I] == 2); };
  }
  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int I : Dep)
  // CHECK-FIXES-NEXT: auto C2 = [&Dep, &I]() { if (I == 2); };
}

} // namespace Lambdas

namespace InitLists {

struct D { int Ii; };
struct E { D Dd; };
int g(int B);

void f() {
  const unsigned N = 3;
  int Array[N];

  // Subtrees of InitListExpr are visited twice. Test that we do not do repeated
  // replacements.
  for (unsigned I = 0; I < N; ++I) {
    int A{ Array[I] };
    int B{ g(Array[I]) };
    int C{ g( { Array[I] } ) };
    D Dd{ { g( { Array[I] } ) } };
    E Ee{ { { g( { Array[I] } ) } } };
  }
  // CHECK-MESSAGES: :[[@LINE-7]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for (int I : Array)
  // CHECK-FIXES-NEXT: int A{ I };
  // CHECK-FIXES-NEXT: int B{ g(I) };
  // CHECK-FIXES-NEXT: int C{ g( { I } ) };
  // CHECK-FIXES-NEXT: D Dd{ { g( { I } ) } };
  // CHECK-FIXES-NEXT: E Ee{ { { g( { I } ) } } };
}

} // namespace InitLists

void bug28341() {
  char v[5];
  for(int i = 0; i < 5; ++i) {
      unsigned char value = v[i];
      if (value > 127)
        ;
  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
  // CHECK-FIXES: for(unsigned char value : v)
  // CHECK-FIXES-NEXT: if (value > 127)
  }
}