1 /* Verify that passing a pointer to a deallocation function that was
2 previously passed to a mismatched reallocation function is diagnosed
3 by -Wmismatched-dealloc (and not by some other warning).
5 { dg-options "-Wall" } */
7 #define A(...) __attribute__ ((malloc (__VA_ARGS__)))
9 typedef __SIZE_TYPE__ size_t;
14 void* realloc (void *, size_t);
17 // User-defined allocator/deallocator just like like realloc.
18 int* int_realloc (size_t, int *);
19 A (int_realloc, 2) int* int_realloc (size_t, int *);
25 void* warn_realloc_op_delete (void *p)
27 void *q = realloc (p, 5); // { dg-message "call to 'void\\* realloc\\(void\\*, size_t\\)'" "note" }
29 operator delete (p); // { dg-warning "'void operator delete\\(void\\*\\)' called on pointer 'p' passed to mismatched allocation function 'void\\* realloc\\(void\\*, size_t\\)' \\\[-Wmismatched-dealloc" }
33 void* warn_realloc_op_delete_cond (void *p)
35 void *q = realloc (p, 5); // { dg-message "call to 'void\\* realloc\\(void\\*, size_t\\)'" "note" }
38 operator delete (p); // { dg-warning "'void operator delete\\(void\\*\\)' called on pointer 'p' passed to mismatched allocation function 'void\\* realloc\\(void\\*, size_t\\)'" }
42 void* warn_realloc_array_delete_char (char *p)
45 q = (char*)realloc (p, 7); // { dg-message "call to 'void\\* realloc\\(void\\*, size_t\\)'" "note" }
48 delete[] (p); // { dg-warning "'void operator delete \\\[]\\(void\\*\\)' called on pointer 'p' passed to mismatched allocation function 'void\\* realloc\\(void\\*, size_t\\)'" }
53 int* warn_int_realloc_op_delete (int *p)
56 q = int_realloc (5, p); // { dg-message "call to 'int\\* int_realloc\\(size_t, int\\*\\)'" "note" }
58 operator delete (p); // { dg-warning "'void operator delete\\(void\\*\\)' called on pointer 'p' passed to mismatched allocation function 'int\\* int_realloc\\(size_t, int\\*\\)' \\\[-Wmismatched-dealloc" }
63 int* warn_int_realloc_free (int *p)
66 q = int_realloc (5, p); // { dg-message "call to 'int\\* int_realloc\\(size_t, int\\*\\)'" "note" }
68 free (p); // { dg-warning "'void free\\(void\\*\\)' called on pointer 'p' passed to mismatched allocation function 'int\\* int_realloc\\(size_t, int\\*\\)' \\\[-Wmismatched-dealloc" }