Fortran: Fix PR 47485.
[gcc.git] / gcc / testsuite / g++.dg / warn / Wmismatched-dealloc-3.C
blob05c7feef5c0f46e521973486961845d8f951f1df
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).
4    { dg-do compile }
5    { dg-options "-Wall" } */
7 #define A(...) __attribute__ ((malloc (__VA_ARGS__)))
9 typedef __SIZE_TYPE__ size_t;
11 extern "C"
13   void free (void *);
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 *);
22 void sink (void *);
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" }
30   return q;
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" }
37   if (!q)
38     operator delete (p);         // { dg-warning "'void operator delete\\(void\\*\\)' called on pointer 'p' passed to mismatched allocation function 'void\\* realloc\\(void\\*, size_t\\)'" }
39   return q;
42 void* warn_realloc_array_delete_char (char *p)
44   char *q;
45   q = (char*)realloc (p, 7);  // { dg-message "call to 'void\\* realloc\\(void\\*, size_t\\)'" "note" }
47   if (!q)
48     delete[] (p);             // { dg-warning "'void operator delete \\\[]\\(void\\*\\)' called on pointer 'p' passed to mismatched allocation function 'void\\* realloc\\(void\\*, size_t\\)'" }
49   return q;
53 int* warn_int_realloc_op_delete (int *p)
55   int *q;
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" }
59   return q;
63 int* warn_int_realloc_free (int *p)
65   int *q;
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" }
69   return q;