handle_constructors_with_new_array.cpp
2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// RUN: %clang_cc1 -fsyntax-only -analyze \
// RUN: -analyzer-checker=core,debug.ExprInspection %s -verify
// These test cases demonstrate lack of Static Analyzer features.
// The FIXME: tags indicate where we expect different output.
// Handle constructors within new[].
// When an array of objects is allocated using the operator new[],
// constructors for all elements of the array are called.
// We should model (potentially some of) such evaluations,
// and the same applies for destructors called from operator delete[].
void clang_analyzer_eval(bool);
struct init_with_list {
int a;
init_with_list() : a(1) {}
};
struct init_in_body {
int a;
init_in_body() { a = 1; }
};
struct init_default_member {
int a = 1;
};
void test_automatic() {
init_with_list a1;
init_in_body a2;
init_default_member a3;
clang_analyzer_eval(a1.a == 1); // expected-warning {{TRUE}}
clang_analyzer_eval(a2.a == 1); // expected-warning {{TRUE}}
clang_analyzer_eval(a3.a == 1); // expected-warning {{TRUE}}
}
void test_dynamic() {
auto *a1 = new init_with_list;
auto *a2 = new init_in_body;
auto *a3 = new init_default_member;
clang_analyzer_eval(a1->a == 1); // expected-warning {{TRUE}}
clang_analyzer_eval(a2->a == 1); // expected-warning {{TRUE}}
clang_analyzer_eval(a3->a == 1); // expected-warning {{TRUE}}
delete a1;
delete a2;
delete a3;
}
void test_automatic_aggregate() {
init_with_list a1[1];
init_in_body a2[1];
init_default_member a3[1];
// FIXME: Should be TRUE, not FALSE.
clang_analyzer_eval(a1[0].a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}}
// FIXME: Should be TRUE, not FALSE.
clang_analyzer_eval(a2[0].a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}}
// FIXME: Should be TRUE, not FALSE.
clang_analyzer_eval(a3[0].a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}}
}
void test_dynamic_aggregate() {
auto *a1 = new init_with_list[1];
auto *a2 = new init_in_body[1];
auto *a3 = new init_default_member[1];
// FIXME: Should be TRUE, not FALSE.
clang_analyzer_eval(a1[0].a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}}
// FIXME: Should be TRUE, not FALSE.
clang_analyzer_eval(a2[0].a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}}
// FIXME: Should be TRUE, not FALSE.
clang_analyzer_eval(a3[0].a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}}
delete[] a1;
delete[] a2;
delete[] a3;
}