blob: a1645a7efe11ced63f9927ad713984d612fbc093 [file] [log] [blame]
Artem Dergachev9d3a7d82018-03-30 19:21:18 +00001// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -std=c++11 -verify %s
2// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -std=c++17 -verify %s
3
4void clang_analyzer_eval(bool);
5
Artem Dergachev1fe52472018-06-14 01:32:46 +00006namespace variable_functional_cast_crash {
7
8struct A {
9 A(int) {}
10};
11
12void foo() {
13 A a = A(0);
14}
15
16struct B {
17 A a;
18 B(): a(A(0)) {}
19};
20
21} // namespace variable_functional_cast_crash
22
23
24namespace address_vector_tests {
25
Artem Dergachev9d3a7d82018-03-30 19:21:18 +000026template <typename T> struct AddressVector {
27 T *buf[10];
28 int len;
29
30 AddressVector() : len(0) {}
31
32 void push(T *t) {
33 buf[len] = t;
34 ++len;
35 }
36};
37
38class ClassWithoutDestructor {
39 AddressVector<ClassWithoutDestructor> &v;
40
41public:
42 ClassWithoutDestructor(AddressVector<ClassWithoutDestructor> &v) : v(v) {
43 v.push(this);
44 }
45
46 ClassWithoutDestructor(ClassWithoutDestructor &&c) : v(c.v) { v.push(this); }
47 ClassWithoutDestructor(const ClassWithoutDestructor &c) : v(c.v) {
48 v.push(this);
49 }
50};
51
52ClassWithoutDestructor make1(AddressVector<ClassWithoutDestructor> &v) {
53 return ClassWithoutDestructor(v);
54}
55ClassWithoutDestructor make2(AddressVector<ClassWithoutDestructor> &v) {
56 return make1(v);
57}
58ClassWithoutDestructor make3(AddressVector<ClassWithoutDestructor> &v) {
59 return make2(v);
60}
61
62void testMultipleReturns() {
63 AddressVector<ClassWithoutDestructor> v;
64 ClassWithoutDestructor c = make3(v);
65
66#if __cplusplus >= 201703L
67 // FIXME: Both should be TRUE.
68 clang_analyzer_eval(v.len == 1); // expected-warning{{TRUE}}
69 clang_analyzer_eval(v.buf[0] == &c); // expected-warning{{FALSE}}
70#else
71 clang_analyzer_eval(v.len == 5); // expected-warning{{TRUE}}
72 clang_analyzer_eval(v.buf[0] != v.buf[1]); // expected-warning{{TRUE}}
73 clang_analyzer_eval(v.buf[1] != v.buf[2]); // expected-warning{{TRUE}}
74 clang_analyzer_eval(v.buf[2] != v.buf[3]); // expected-warning{{TRUE}}
75 clang_analyzer_eval(v.buf[3] != v.buf[4]); // expected-warning{{TRUE}}
76 clang_analyzer_eval(v.buf[4] == &c); // expected-warning{{TRUE}}
77#endif
78}
Artem Dergachev1fe52472018-06-14 01:32:46 +000079
80} // namespace address_vector_tests