From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4CB893858025; Fri, 28 Jan 2022 11:43:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CB893858025 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/104142] [9/10/11/12 Regression] Spurios warning unused-variable on const static variable and defaulted constructor Date: Fri, 28 Jan 2022 11:43:38 +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: 12.0 X-Bugzilla-Keywords: diagnostic, needs-bisection X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 9.5 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: Fri, 28 Jan 2022 11:43:38 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104142 Jakub Jelinek changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |mpolacek at gcc dot gnu.or= g, | |ppalka at gcc dot gnu.org --- Comment #4 from Jakub Jelinek --- If we want the same warning, we'd need to probably special case const vars = with defaulted default ctors and empty classes, if it isn't empty class, both of these are rejected already: pr104142.C:2:16: error: uninitialized =E2=80=98const a=E2=80=99 [-fpermissi= ve] 2 | static const A a; | ^ pr104142.C:1:8: note: =E2=80=98const struct A=E2=80=99 has no user-provided= default constructor 1 | struct A { int a; }; | ^ pr104142.C:1:16: note: and the implicitly-defined constructor does not initialize =E2=80=98int A::a=E2=80=99 1 | struct A { int a; }; | ^ pr104142.C:5:16: error: uninitialized =E2=80=98const b=E2=80=99 [-fpermissi= ve] 5 | static const B b; | ^ pr104142.C:4:8: note: =E2=80=98const struct B=E2=80=99 has no user-provided= default constructor 4 | struct B { B()=3Ddefault; int b; }; | ^ pr104142.C:4:12: note: constructor is not user-provided because it is explicitly defaulted in the class body 4 | struct B { B()=3Ddefault; int b; }; | ^ pr104142.C:4:29: note: and the implicitly-defined constructor does not initialize =E2=80=98int B::b=E2=80=99 4 | struct B { B()=3Ddefault; int b; }; | ^=