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