Artem Dergachev | f119bf9 | 2018-02-27 22:05:55 +0000 | [diff] [blame^] | 1 | // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -verify %s |
| 2 | |
| 3 | namespace implicit_constructor { |
| 4 | struct S { |
| 5 | public: |
| 6 | S() {} |
| 7 | S(const S &) {} |
| 8 | }; |
| 9 | |
| 10 | // Warning is in a weird position because the body of the constructor is |
| 11 | // missing. Specify which field is being assigned. |
| 12 | class C { // expected-warning{{Value assigned to field 'y' in implicit constructor is garbage or undefined}} |
| 13 | // expected-note@-1{{Value assigned to field 'y' in implicit constructor is garbage or undefined}} |
| 14 | int x, y; |
| 15 | S s; |
| 16 | |
| 17 | public: |
| 18 | C(): x(0) {} |
| 19 | }; |
| 20 | |
| 21 | void test() { |
| 22 | C c1; |
| 23 | C c2(c1); // expected-note{{Calling implicit copy constructor for 'C'}} |
| 24 | } |
| 25 | } // end namespace implicit_constructor |
| 26 | |
| 27 | |
| 28 | namespace explicit_constructor { |
| 29 | class C { |
| 30 | int x, y; |
| 31 | |
| 32 | public: |
| 33 | C(): x(0) {} |
| 34 | // It is not necessary to specify which field is being assigned to. |
| 35 | C(const C &c): |
| 36 | x(c.x), |
| 37 | y(c.y) // expected-warning{{Assigned value is garbage or undefined}} |
| 38 | // expected-note@-1{{Assigned value is garbage or undefined}} |
| 39 | {} |
| 40 | }; |
| 41 | |
| 42 | void test() { |
| 43 | C c1; |
| 44 | C c2(c1); // expected-note{{Calling copy constructor for 'C'}} |
| 45 | } |
| 46 | } // end namespace explicit_constructor |
| 47 | |
| 48 | |
| 49 | namespace base_class_constructor { |
| 50 | struct S { |
| 51 | public: |
| 52 | S() {} |
| 53 | S(const S &) {} |
| 54 | }; |
| 55 | |
| 56 | class C { // expected-warning{{Value assigned to field 'y' in implicit constructor is garbage or undefined}} |
| 57 | // expected-note@-1{{Value assigned to field 'y' in implicit constructor is garbage or undefined}} |
| 58 | int x, y; |
| 59 | S s; |
| 60 | |
| 61 | public: |
| 62 | C(): x(0) {} |
| 63 | }; |
| 64 | |
| 65 | class D: public C { |
| 66 | public: |
| 67 | D(): C() {} |
| 68 | }; |
| 69 | |
| 70 | void test() { |
| 71 | D d1; |
| 72 | D d2(d1); // expected-note {{Calling implicit copy constructor for 'D'}} |
| 73 | // expected-note@-1{{Calling implicit copy constructor for 'C'}} |
| 74 | } |
| 75 | } // end namespace base_class_constructor |