blob: 5a14f3025d43142c6ebce51e05ef94b9bf45379a [file] [log] [blame]
Jordan Roseda5fc532012-07-26 20:04:00 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc -analyzer-store region -analyzer-ipa=inlining -cfg-add-implicit-dtors -cfg-add-initializers -verify %s
Zhongxing Xub13453b2010-11-20 06:53:12 +00002
3class A {
4public:
5 ~A() {
6 int *x = 0;
7 *x = 3; // expected-warning{{Dereference of null pointer}}
8 }
9};
10
11int main() {
12 A a;
13}
Jordan Roseda5fc532012-07-26 20:04:00 +000014
15
16typedef __typeof(sizeof(int)) size_t;
17void *malloc(size_t);
18void free(void *);
19
20class SmartPointer {
21 void *X;
22public:
23 SmartPointer(void *x) : X(x) {}
24 ~SmartPointer() {
25 free(X);
26 }
27};
28
29void testSmartPointer() {
30 char *mem = (char*)malloc(4);
31 {
32 SmartPointer Deleter(mem);
33 // destructor called here
34 }
35 *mem = 0; // expected-warning{{Use of memory after it is freed}}
36}