76 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -verify %s2 3namespace implicit_constructor {4struct S {5public:6 S() {}7 S(const S &) {}8};9 10// Warning is in a weird position because the body of the constructor is11// missing. Specify which field is being assigned.12class C { // expected-warning{{Value assigned to field 'y' in implicit constructor is uninitialized}}13 // expected-note@-1{{Value assigned to field 'y' in implicit constructor is uninitialized}}14 int x, y;15 S s;16 17public:18 C(): x(0) {}19};20 21void test() {22 C c1;23 C c2(c1); // expected-note{{Calling implicit copy constructor for 'C'}}24}25} // end namespace implicit_constructor26 27 28namespace explicit_constructor {29class C {30 int x, y;31 32public: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 uninitialized}}38 // expected-note@-1{{Assigned value is uninitialized}}39 {}40};41 42void test() {43 C c1;44 C c2(c1); // expected-note{{Calling copy constructor for 'C'}}45}46} // end namespace explicit_constructor47 48 49namespace base_class_constructor {50struct S {51public:52 S() {}53 S(const S &) {}54};55 56class C { // expected-warning{{Value assigned to field 'y' in implicit constructor is uninitialized}}57 // expected-note@-1{{Value assigned to field 'y' in implicit constructor is uninitialized}}58 int x, y;59 S s;60 61public:62 C(): x(0) {}63};64 65class D: public C {66public:67 D(): C() {}68};69 70void 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_constructor76