aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp1z/range-for1.C
blob: 4bca986d3b55a8eb69685f92a36ccce42e4a4677 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// P0184R0: Generalizing the Range-Based For Loop
// { dg-do compile { target c++17 } }

struct A {
  int ar[4];
  int *begin() { return ar; }
  struct end_t {
    int *p;
    friend bool operator!= (int *p, end_t e) { return p != e.p; }
  };
  end_t end() { return { &ar[4] }; }
};

int main()
{
  A a { 1, 2, 3, 4 };
  int i = 1;
  for (auto x: a)
    if (x != i++)
      __builtin_abort ();
  if (i != 5)
    __builtin_abort ();
}