1 /* { dg-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fanalyzer-checker=malloc -fdiagnostics-show-caret" } */
2 /* { dg-skip-if "requires hosted libstdc++ for cstdlib malloc" { ! hostedlib } } */
3 /* { dg-enable-nn-line-numbers "" } */
9 virtual void allocate ();
10 virtual void deallocate ();
13 struct Derived: public Base
18 ptr = (int*)malloc(sizeof(int));
33 base_ptr->deallocate();
34 int n = *D.ptr; /* { dg-warning "use after 'free' of 'D.Derived::ptr'" } */
37 /* use after 'free' */
38 /* { dg-begin-multiline-output "" }
41 'void test()': events 1-2
46 | | (1) entry to 'test'
51 | | (2) calling 'Derived::allocate' from 'test'
53 +--> 'virtual void Derived::allocate()': events 3-4
55 | NN | void allocate ()
58 | | (3) entry to 'Derived::allocate'
60 | NN | ptr = (int*)malloc(sizeof(int));
61 | | ~~~~~~~~~~~~~~~~~~~
63 | | (4) allocated here
67 'void test()': events 5-6
72 | | (5) returning to 'test' from 'Derived::allocate'
73 | NN | base_ptr->deallocate();
74 | | ~~~~~~~~~~~~~~~~~~~~~~
76 | | (6) calling 'Derived::deallocate' from 'test'
78 +--> 'virtual void Derived::deallocate()': events 7-8
80 | NN | void deallocate ()
83 | | (7) entry to 'Derived::deallocate'
92 'void test()': events 9-10
94 | NN | base_ptr->deallocate();
95 | | ~~~~~~~~~~~~~~~~~~~~^~
97 | | (9) returning to 'test' from 'Derived::deallocate'
98 | NN | int n = *D.ptr;
101 | | (10) use after 'free' of 'D.Derived::ptr'; freed at (8)
103 { dg-end-multiline-output "" } */