annotate gcc/testsuite/g++.old-deja/g++.mike/p11667.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // { dg-do run { xfail sparc64-*-elf arm-*-pe } }
kono
parents:
diff changeset
2 // { dg-options "-fexceptions" }
kono
parents:
diff changeset
3 // prms-id: 11667
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 extern "C" int printf(const char *,...);
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 template < class T >
kono
parents:
diff changeset
8 class LIST {
kono
parents:
diff changeset
9 public:
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 LIST() { nitems = 16; items = new T[nitems]; };
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 LIST(int u) { nitems = u; items = new T[nitems]; };
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 T& operator[](int i) const {
kono
parents:
diff changeset
16 return items[i];
kono
parents:
diff changeset
17 }
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 void grow(int n) {
kono
parents:
diff changeset
20 T* newlist = new T[n];
kono
parents:
diff changeset
21 T* src = items;
kono
parents:
diff changeset
22 T* dst = newlist;
kono
parents:
diff changeset
23 int i = nitems;
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 try {
kono
parents:
diff changeset
26 while (i--) *dst++ = *src++;
kono
parents:
diff changeset
27 } catch (...) {
kono
parents:
diff changeset
28 delete[] newlist;
kono
parents:
diff changeset
29 throw;
kono
parents:
diff changeset
30 }
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 if (items) delete[] items;
kono
parents:
diff changeset
33 nitems = n;
kono
parents:
diff changeset
34 items = newlist;
kono
parents:
diff changeset
35 }
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 private:
kono
parents:
diff changeset
38 int nitems;
kono
parents:
diff changeset
39 T *items;
kono
parents:
diff changeset
40 };
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 int main(int argc, char **argv) {
kono
parents:
diff changeset
43 int i;
kono
parents:
diff changeset
44 LIST<int> mylist(10);
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 printf("Start dumping initial 10 item list\n");
kono
parents:
diff changeset
47 for (i = 0; i < 10 ; i++) {
kono
parents:
diff changeset
48 mylist[i] = i;
kono
parents:
diff changeset
49 printf("%d\n", mylist[i]);
kono
parents:
diff changeset
50 }
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 printf("Growing list to 20\n");
kono
parents:
diff changeset
53 mylist.grow(20);
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 printf("Start dumping grown 20 item list\n");
kono
parents:
diff changeset
56 for (i = 0; i < 20; i++) {
kono
parents:
diff changeset
57 mylist[i] = i;
kono
parents:
diff changeset
58 printf("%d\n", mylist[i]);
kono
parents:
diff changeset
59 }
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 return 0;
kono
parents:
diff changeset
62 }