annotate clang/test/Analysis/NewDeleteLeaks-PR19102.cpp @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 79ff65ed7e25
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 class A0 {};
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 class A1 {
anatofuz
parents:
diff changeset
6 public:
anatofuz
parents:
diff changeset
7 A1(int);
anatofuz
parents:
diff changeset
8 };
anatofuz
parents:
diff changeset
9
anatofuz
parents:
diff changeset
10 struct S{
anatofuz
parents:
diff changeset
11 int i;
anatofuz
parents:
diff changeset
12 };
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 class A2 {
anatofuz
parents:
diff changeset
15 public:
anatofuz
parents:
diff changeset
16 A2();
anatofuz
parents:
diff changeset
17 A2(S);
anatofuz
parents:
diff changeset
18 A2(int*);
anatofuz
parents:
diff changeset
19 A2(S*);
anatofuz
parents:
diff changeset
20 A2(S&, int);
anatofuz
parents:
diff changeset
21 A2(int, S**);
anatofuz
parents:
diff changeset
22 };
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 void test() {
anatofuz
parents:
diff changeset
25 new int; // expected-warning@+1 {{Potential memory leak}}
anatofuz
parents:
diff changeset
26 new A0; // expected-warning@+1 {{Potential memory leak}}
anatofuz
parents:
diff changeset
27 new A1(0); // expected-warning@+1 {{Potential memory leak}}
anatofuz
parents:
diff changeset
28 new A2; // expected-warning@+1 {{Potential memory leak}}
anatofuz
parents:
diff changeset
29 S s;
anatofuz
parents:
diff changeset
30 s.i = 1;
anatofuz
parents:
diff changeset
31 S* ps = new S;
anatofuz
parents:
diff changeset
32 new A2(s); // expected-warning@+1 {{Potential memory leak}}
anatofuz
parents:
diff changeset
33 new A2(&(s.i)); // expected-warning@+1 {{Potential memory leak}}
anatofuz
parents:
diff changeset
34 new A2(ps); // no warning
anatofuz
parents:
diff changeset
35 new A2(*ps, 1); // no warning
anatofuz
parents:
diff changeset
36 new A2(1, &ps); // no warning
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 // Tests to ensure that leaks are reported for consumed news no matter what the arguments are.
anatofuz
parents:
diff changeset
39 A2 *a2p1 = new A2; // expected-warning@+1 {{Potential leak of memory}}
anatofuz
parents:
diff changeset
40 A2 *a2p2 = new A2(ps); // expected-warning@+1 {{Potential leak of memory}}
anatofuz
parents:
diff changeset
41 A2 *a2p3 = new A2(*ps, 1); // expected-warning@+1 {{Potential leak of memory}}
anatofuz
parents:
diff changeset
42 A2 *a2p4 = new A2(1, &ps); // expected-warning@+1 {{Potential leak of memory}}
anatofuz
parents:
diff changeset
43 }