From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 388EB3858034; Thu, 12 Nov 2020 15:07:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 388EB3858034 From: "mpolacek at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/19808] miss a warning about uninitialized member usage in member initializer list in constructor Date: Thu, 12 Nov 2020 15:07:12 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 3.4.4 X-Bugzilla-Keywords: diagnostic, easyhack, patch X-Bugzilla-Severity: enhancement X-Bugzilla-Who: mpolacek at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Nov 2020 15:07:13 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D19808 Marek Polacek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |mpolacek at gcc dot gnu.org --- Comment #48 from Marek Polacek --- I have a patch that for this: // PR c++/19808 // { dg-do compile { target c++11 } } // { dg-options "-Wuninitialized" } struct S { int i, j, k, l; S() : i(j), // { dg-warning "field .S::j. is uninitialized when used here= " } j(1), k(l + 1), // { dg-warning "field .S::l. is uninitialized when used here" } l(2) { } }; struct A { int a, b, c; A() : a(b // { dg-warning "field .A::b. is uninitialized when used here" } + c) { } // { dg-warning "field .A::c. is uninitialized when used here" } }; struct B { int &r; int *p; int a; B() : r(a), p(&a), a(1) { } }; struct C { const int &r1, &r2; C () : r1(r2), // { dg-warning "reference .C::r2. is not yet bound to a v= alue when used here" } r2(r1) { } }; struct D { int a =3D 1; int b =3D 2; D() : a(b + 1), b(a + 1) { } // { dg-warning "field .D::b. is uninitializ= ed when used here" } }; struct E { int a =3D 1; E() : a(a + 1) { } // { dg-warning "field .E::a. is uninitialized when us= ed here" } }; struct F { int a =3D 1; int b; F() : b(a + 1) { } }; struct bar { bar() {} bar(bar&) {} }; class foo { bar first; bar second; public: foo() : first(second) {} // { dg-warning "field .foo::second. is uninitialized when used here" } }; does this: $ ./cc1plus -quiet -Wuninitialized Wuninitialized-12.C Wuninitialized-12.C: In constructor =E2=80=98S::S()=E2=80=99: Wuninitialized-12.C:7:11: warning: field =E2=80=98S::j=E2=80=99 is uninitia= lized when used here [-Wuninitialized] 7 | S() : i(j), // { dg-warning "field .S::j. is uninitialized when u= sed here" } | ^ Wuninitialized-12.C:9:11: warning: field =E2=80=98S::l=E2=80=99 is uninitia= lized when used here [-Wuninitialized] 9 | k(l + 1), // { dg-warning "field .S::l. is uninitialized wh= en used here" } | ^ Wuninitialized-12.C: In constructor =E2=80=98A::A()=E2=80=99: Wuninitialized-12.C:15:11: warning: field =E2=80=98A::b=E2=80=99 is uniniti= alized when used here [-Wuninitialized] 15 | A() : a(b // { dg-warning "field .A::b. is uninitialized when used here" } | ^ Wuninitialized-12.C:16:13: warning: field =E2=80=98A::c=E2=80=99 is uniniti= alized when used here [-Wuninitialized] 16 | + c) { } // { dg-warning "field .A::c. is uninitialized w= hen used here" } | ^ Wuninitialized-12.C: In constructor =E2=80=98C::C()=E2=80=99: Wuninitialized-12.C:28:13: warning: reference =E2=80=98C::r2=E2=80=99 is no= t yet bound to a value when used here [-Wuninitialized] 28 | C () : r1(r2), // { dg-warning "reference .C::r2. is not yet boun= d to a value when used here" } | ^~ Wuninitialized-12.C: In constructor =E2=80=98D::D()=E2=80=99: Wuninitialized-12.C:35:11: warning: field =E2=80=98D::b=E2=80=99 is uniniti= alized when used here [-Wuninitialized] 35 | D() : a(b + 1), b(a + 1) { } // { dg-warning "field .D::b. is uninitialized when used here" } | ^ Wuninitialized-12.C: In constructor =E2=80=98E::E()=E2=80=99: Wuninitialized-12.C:40:11: warning: field =E2=80=98E::a=E2=80=99 is uniniti= alized when used here [-Wuninitialized] 40 | E() : a(a + 1) { } // { dg-warning "field .E::a. is uninitialized when used here" } | ^ Wuninitialized-12.C: In constructor =E2=80=98foo::foo()=E2=80=99: Wuninitialized-12.C:58:17: warning: field =E2=80=98foo::second=E2=80=99 is = uninitialized when used here [-Wuninitialized] 58 | foo() : first(second) {} // { dg-warning "field .foo::second. is uninitialized when used here" } | ^~~~~~=