Debian Codegraph @

gcc/testsuite/g++.dg/analyzer/new-vs-malloc.C

raw
1 /* { dg-skip-if "requires hosted libstdc++ for cstdlib free" { ! hostedlib } } */
2
3 #include <cstdlib>
4
5 struct s {};
6
7 void test_1 ()
8 {
9 s *p = new s; // { dg-message "allocated here \\(expects deallocation with 'delete'\\)"
10 free (p); // { dg-warning "'p' should have been deallocated with 'delete' but was deallocated with 'free'" }
11 }
12
13 void test_2 ()
14 {
15 char *p = new char[16]; // { dg-message "allocated here \\(expects deallocation with 'delete\\\[\\\]'\\)"
16 free (p); // { dg-warning "'p' should have been deallocated with 'delete\\\[\\\]' but was deallocated with 'free'" }
17 }
18
19 void test_3 ()
20 {
21 char *p = (char *)malloc (16); // { dg-message "allocated here \\(expects deallocation with 'free'\\)"
22 delete[] p; // { dg-warning "'p' should have been deallocated with 'free' but was deallocated with 'delete\\\[\\\]'" }
23 }