c++: prvalue of array type [PR111286]
[official-gcc.git] / gcc / testsuite / c-c++-common / Wfree-nonheap-object-2.c
bloba2dbd181e3310aa5b6fe6f8937520557bf62e40b
1 /* PR middle-end/98166: bogus -Wmismatched-dealloc on user-defined allocator
2 and inlining
3 Verify that the allocator can be declared inline without a warning when
4 it's associated with a standard deallocator. Associating an inline
5 deallocator with an allocator would cause false positives when the former
6 calls a deallocation function the allocator isn't associated with, so
7 that triggers a warning on declaration.
8 { dg-do compile }
9 { dg-options "-O2 -Wall" } */
11 __attribute__ ((malloc (__builtin_free)))
12 inline int*
13 alloc_int (int n)
15 return (int*)__builtin_malloc (n + sizeof (int));
18 void test_nowarn_int (int n)
21 int *p = alloc_int (n);
22 __builtin_free (p);
26 int *p = alloc_int (n);
27 __builtin_free (p + 1); // { dg-warning "\\\[-Wfree-nonheap-object" }
32 inline void
33 dealloc_long (long *p)
35 __builtin_free (p); // { dg-warning "'(__builtin_free|void __builtin_free\\(void\\*\\))' called on pointer '(p|<unknown>)' with nonzero offset" }
38 __attribute__ ((malloc (dealloc_long)))
39 long* alloc_long (int); // { dg-warning "'malloc \\\(dealloc_long\\\)' attribute ignored with deallocation functions declared 'inline'" }
41 void test_nowarn_long (int n)
44 long *p = alloc_long (n);
45 dealloc_long (p);
49 long *p = alloc_long (n);
50 dealloc_long (p + 1);