| 1 |
// { dg-skip-if "requires hosted libstdc++ for cstdio" { ! hostedlib } } |
| 2 |
#include <cstdio> |
| 3 |
#include <cstdlib> |
| 4 |
|
| 5 |
struct A |
| 6 |
{ |
| 7 |
int m_data; |
| 8 |
A() {m_data = 0;} |
| 9 |
virtual int deallocate (void) |
| 10 |
{ |
| 11 |
return 42; |
| 12 |
} |
| 13 |
}; |
| 14 |
|
| 15 |
struct B: public A |
| 16 |
{ |
| 17 |
int *ptr; |
| 18 |
int m_data_b; |
| 19 |
B() {m_data_b = 0;} |
| 20 |
void allocate () |
| 21 |
{ |
| 22 |
ptr = (int*)malloc(sizeof(int)); |
| 23 |
} |
| 24 |
int deallocate (void) |
| 25 |
{ |
| 26 |
free(ptr); |
| 27 |
return 0; |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
void foo(A *a_ptr) |
| 32 |
{ |
| 33 |
printf("%d\n",a_ptr->deallocate()); |
| 34 |
} |
| 35 |
|
| 36 |
void test() |
| 37 |
{ |
| 38 |
B b; |
| 39 |
A a, *aptr; |
| 40 |
aptr = &b; |
| 41 |
b.allocate(); |
| 42 |
foo(aptr); |
| 43 |
aptr = &a; |
| 44 |
foo(aptr); |
| 45 |
} |