| 1 |
/* { dg-skip-if "requires hosted libstdc++ for cstdlib malloc" { ! hostedlib } } */ |
| 2 |
|
| 3 |
#include <cstdlib> |
| 4 |
|
| 5 |
struct A |
| 6 |
{ |
| 7 |
virtual int foo (void) |
| 8 |
{ |
| 9 |
return 42; |
| 10 |
} |
| 11 |
}; |
| 12 |
|
| 13 |
struct B: public A |
| 14 |
{ |
| 15 |
int *ptr; |
| 16 |
void alloc () |
| 17 |
{ |
| 18 |
ptr = (int*)malloc(sizeof(int)); |
| 19 |
} |
| 20 |
int foo (void) |
| 21 |
{ |
| 22 |
free(ptr); /* { dg-warning "double-'free' of 'b.B::ptr'" } */ |
| 23 |
return 0; |
| 24 |
} |
| 25 |
}; |
| 26 |
|
| 27 |
int test () |
| 28 |
{ |
| 29 |
struct B b, *bptr=&b; |
| 30 |
b.alloc (); |
| 31 |
bptr->foo (); /* { dg-message "\\(6\\) calling 'B::foo' from 'test'" "event 6" } */ |
| 32 |
/* { dg-message "\\(9\\) returning to 'test' from 'B::foo'" "event 9" { target *-*-* } .-1 } */ |
| 33 |
return bptr->foo (); |
| 34 |
} |