1 | // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete -verify %s |
2 | |
3 | #include "Inputs/system-header-simulator-cxx.h" |
4 | |
5 | struct S { |
6 | S() : Data(new int) {} |
7 | ~S() { delete Data; } |
8 | int *getData() { return Data; } |
9 | |
10 | private: |
11 | int *Data; |
12 | }; |
13 | |
14 | int *freeAfterReturnTemp() { |
15 | return S().getData(); // expected-warning {{Use of memory after it is freed}} |
16 | } |
17 | |
18 | int *freeAfterReturnLocal() { |
19 | S X; |
20 | return X.getData(); // expected-warning {{Use of memory after it is freed}} |
21 | } |
22 | |