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 | |
| 24 | namespace address_vector_tests { |
| 25 | |
Artem Dergachev | 9d3a7d8 | 2018-03-30 19:21:18 +0000 | [diff] [blame] | 26 | template <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 | |
| 38 | class ClassWithoutDestructor { |
| 39 | AddressVector<ClassWithoutDestructor> &v; |
| 40 | |
| 41 | public: |
| 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 | |
| 52 | ClassWithoutDestructor make1(AddressVector<ClassWithoutDestructor> &v) { |
| 53 | return ClassWithoutDestructor(v); |
| 54 | } |
| 55 | ClassWithoutDestructor make2(AddressVector<ClassWithoutDestructor> &v) { |
| 56 | return make1(v); |
| 57 | } |
| 58 | ClassWithoutDestructor make3(AddressVector<ClassWithoutDestructor> &v) { |
| 59 | return make2(v); |
| 60 | } |
| 61 | |
| 62 | void 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 Dergachev | 1fe5247 | 2018-06-14 01:32:46 +0000 | [diff] [blame^] | 79 | |
| 80 | } // namespace address_vector_tests |