summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/cpp11-migrate/LoopConvert/nesting.cpp
blob: 729b5ff21a68541e1c89e5aae7cbbfd1c0d488c9 (plain)
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
// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
// RUN: cpp11-migrate -loop-convert %t.cpp -- -I %S/Inputs
// RUN: FileCheck -input-file=%t.cpp %s

#include "structures.h"

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: for (auto & elem : Arr)
  // CHECK-NEXT: for (auto & Arr_j : Arr)
  // CHECK-NEXT: int k = elem.x + Arr_j.x;
  // CHECK-NOT: int l = elem.x + elem.x;

  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);
    }
  }
  // The inner loop is also convertible, but doesn't need to be converted
  // immediately. Update this test when that changes!
  // CHECK: for (auto & elem : Nest)
  // CHECK-NEXT: for (int j = 0; j < M; ++j)
  // CHECK-NEXT: printf("Got item %d", elem[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-NOT: for (auto & {{[a-zA-Z_]+}} : Nest[i])
  // CHECK: for (int j = 0; j < M; ++j)
  // CHECK-NEXT: for (auto & elem : Nest)
  // CHECK-NEXT: printf("Got item %d", elem[j].x);
  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);
    }
  }
  // The inner loop is also convertible, but doesn't need to be converted
  // immediately. Update this test when that changes!
  // CHECK: for (auto & elem : NestT) {
  // CHECK-NEXT: for (T::iterator TI = (elem).begin(), TE = (elem).end(); TI != TE; ++TI) {
  // CHECK-NEXT: printf("%d", *TI);
}
OpenPOWER on IntegriCloud