Artem Dergachev | 9d3a7d8 | 2018-03-30 19:21:18 +0000 | [diff] [blame] | 1 | // 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 | |
| 4 | void clang_analyzer_eval(bool); |
| 5 | |
Artem Dergachev | 1fe5247 | 2018-06-14 01:32:46 +0000 | [diff] [blame] | 6 | namespace variable_functional_cast_crash { |
| 7 | |
| 8 | struct A { |
| 9 | A(int) {} |
| 10 | }; |
| 11 | |
| 12 | void foo() { |
| 13 | A a = A(0); |
| 14 | } |
| 15 | |
| 16 | struct B { |
| 17 | A a; |
| 18 | B(): a(A(0)) {} |
| 19 | }; |
| 20 | |
| 21 | } // namespace variable_functional_cast_crash |
| 22 | |
| 23 | |
Artem Dergachev | a84374d | 2018-06-14 01:40:49 +0000 | [diff] [blame^] | 24 | namespace ctor_initializer { |
| 25 | |
| 26 | struct S { |
| 27 | int x, y, z; |
| 28 | }; |
| 29 | |
| 30 | struct T { |
| 31 | S s; |
| 32 | int w; |
| 33 | T(int w): s(), w(w) {} |
| 34 | }; |
| 35 | |
| 36 | class C { |
| 37 | T t; |
| 38 | public: |
| 39 | C() : t(T(4)) { |
| 40 | S s = {1, 2, 3}; |
| 41 | t.s = s; |
| 42 | // FIXME: Should be TRUE in C++11 as well. |
| 43 | clang_analyzer_eval(t.w == 4); |
| 44 | #if __cplusplus >= 201703L |
| 45 | // expected-warning@-2{{TRUE}} |
| 46 | #else |
| 47 | // expected-warning@-4{{UNKNOWN}} |
| 48 | #endif |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | } // namespace ctor_initializer |
| 53 | |
| 54 | |
Artem Dergachev | 1fe5247 | 2018-06-14 01:32:46 +0000 | [diff] [blame] | 55 | namespace address_vector_tests { |
| 56 | |
Artem Dergachev | 9d3a7d8 | 2018-03-30 19:21:18 +0000 | [diff] [blame] | 57 | template <typename T> struct AddressVector { |
| 58 | T *buf[10]; |
| 59 | int len; |
| 60 | |
| 61 | AddressVector() : len(0) {} |
| 62 | |
| 63 | void push(T *t) { |
| 64 | buf[len] = t; |
| 65 | ++len; |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | class ClassWithoutDestructor { |
| 70 | AddressVector<ClassWithoutDestructor> &v; |
| 71 | |
| 72 | public: |
| 73 | ClassWithoutDestructor(AddressVector<ClassWithoutDestructor> &v) : v(v) { |
| 74 | v.push(this); |
| 75 | } |
| 76 | |
| 77 | ClassWithoutDestructor(ClassWithoutDestructor &&c) : v(c.v) { v.push(this); } |
| 78 | ClassWithoutDestructor(const ClassWithoutDestructor &c) : v(c.v) { |
| 79 | v.push(this); |
| 80 | } |
| 81 | }; |
| 82 | |
| 83 | ClassWithoutDestructor make1(AddressVector<ClassWithoutDestructor> &v) { |
| 84 | return ClassWithoutDestructor(v); |
| 85 | } |
| 86 | ClassWithoutDestructor make2(AddressVector<ClassWithoutDestructor> &v) { |
| 87 | return make1(v); |
| 88 | } |
| 89 | ClassWithoutDestructor make3(AddressVector<ClassWithoutDestructor> &v) { |
| 90 | return make2(v); |
| 91 | } |
| 92 | |
| 93 | void testMultipleReturns() { |
| 94 | AddressVector<ClassWithoutDestructor> v; |
| 95 | ClassWithoutDestructor c = make3(v); |
| 96 | |
| 97 | #if __cplusplus >= 201703L |
| 98 | // FIXME: Both should be TRUE. |
| 99 | clang_analyzer_eval(v.len == 1); // expected-warning{{TRUE}} |
| 100 | clang_analyzer_eval(v.buf[0] == &c); // expected-warning{{FALSE}} |
| 101 | #else |
| 102 | clang_analyzer_eval(v.len == 5); // expected-warning{{TRUE}} |
| 103 | clang_analyzer_eval(v.buf[0] != v.buf[1]); // expected-warning{{TRUE}} |
| 104 | clang_analyzer_eval(v.buf[1] != v.buf[2]); // expected-warning{{TRUE}} |
| 105 | clang_analyzer_eval(v.buf[2] != v.buf[3]); // expected-warning{{TRUE}} |
| 106 | clang_analyzer_eval(v.buf[3] != v.buf[4]); // expected-warning{{TRUE}} |
| 107 | clang_analyzer_eval(v.buf[4] == &c); // expected-warning{{TRUE}} |
| 108 | #endif |
| 109 | } |
Artem Dergachev | 1fe5247 | 2018-06-14 01:32:46 +0000 | [diff] [blame] | 110 | |
| 111 | } // namespace address_vector_tests |