summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.mike/p11667.C
blob: 802c0cf9b665474e38e0dc5290d3a1741c00e257 (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
58
59
60
61
62
// { dg-do run { xfail sparc64-*-elf arm-*-pe } }
// { dg-options "-fexceptions" }
// prms-id: 11667

extern "C" int printf(const char *,...);

template < class T >
class LIST {
public:

  LIST() { nitems = 16; items = new T[nitems]; };

  LIST(int u) { nitems = u; items = new T[nitems]; };

  T& operator[](int i) const {
    return items[i];
  }

  void grow(int n) {
    T* newlist = new T[n];
    T* src = items;
    T* dst = newlist;
    int i = nitems;

    try {
      while (i--) *dst++ = *src++;
    } catch (...) {
      delete[]  newlist;
      throw;
    }

    if (items) delete[] items;
    nitems = n;
    items = newlist;
  }

private:
  int nitems;
  T *items;
};

int main(int argc, char **argv) {
  int i;
  LIST<int> mylist(10);

  printf("Start dumping initial 10 item list\n");
  for (i = 0; i < 10 ; i++) {
    mylist[i] = i;
    printf("%d\n", mylist[i]);
  }

  printf("Growing list to 20\n");
  mylist.grow(20);

  printf("Start dumping grown 20 item list\n");
  for (i = 0; i < 20; i++) {
    mylist[i] = i;
    printf("%d\n", mylist[i]);
  }

  return 0;
}