1 // { dg-do assemble }
2 // GROUPS passed operators
3 #include <iostream>
4
5 //
6 // ffrees space allocated for N-D array
7 //
8
9 template <class T>
ffree(long rows,T ** array)10 void ffree(long rows, T** array)
11 {
12 for( long i = 0; i < rows; i++ )
13 delete [] array[i]; // delete row
14 delete [] array; // delete outer array
15 }
16
17 template <class T>
allocate1d(long size,T * & array)18 T* allocate1d(long size, T*& array)
19 {
20 return array = new T[size];
21 }
22
23 template <class T>
allocate2d(long d1,long d2,T ** & array)24 T** allocate2d(long d1, long d2, T**& array)
25 {
26 if( allocate1d(d1, array) != 0 )
27 {
28 for( long i = 0; i < d1; i++ )
29 {
30 if( allocate1d(d2, array[i]) == 0 )
31 {
32 ffree(i,array);
33 return array;
34 }
35 }
36 }
37 return array;
38 }
39
main()40 int main()
41 {
42 long d1 = 3, d2 = 4;
43 class foo
44 {
45 public:
46 foo() {std::cout << "foo created" << std::endl; }
47
48 ~foo() {std::cout << "foo deleted" << std::endl; }
49 };
50
51 foo **f2;
52 allocate2d(d1, d2, f2);// { dg-error "" } type.*// ERROR - trying to.*
53 ffree(d1, f2);// { dg-error "" } type.*// ERROR - trying to.*
54
55 }
56