2018-08-03 07:02:08 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete -verify %s
|
|
|
|
|
|
|
|
#include "Inputs/system-header-simulator-cxx.h"
|
|
|
|
|
|
|
|
struct S {
|
|
|
|
S() : Data(new int) {}
|
|
|
|
~S() { delete Data; }
|
|
|
|
int *getData() { return Data; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int *Data;
|
|
|
|
};
|
|
|
|
|
|
|
|
int *freeAfterReturnTemp() {
|
|
|
|
return S().getData(); // expected-warning {{Use of memory after it is freed}}
|
|
|
|
}
|
|
|
|
|
|
|
|
int *freeAfterReturnLocal() {
|
|
|
|
S X;
|
2018-09-22 04:36:41 +08:00
|
|
|
return X.getData(); // expected-warning {{Use of memory after it is freed}}
|
|
|
|
}
|