From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 24E3D3858D35; Fri, 10 Dec 2021 05:55:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24E3D3858D35 From: "egallager at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/87656] Useful flags to enable with -Wall or -Wextra Date: Fri, 10 Dec 2021 05:55:05 +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: unknown X-Bugzilla-Keywords: diagnostic, meta-bug X-Bugzilla-Severity: enhancement X-Bugzilla-Who: egallager 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: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: 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, 10 Dec 2021 05:55:06 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D87656 --- Comment #10 from Eric Gallager --- (In reply to Segher Boessenkool from comment #9) > (In reply to Eric Gallager from comment #8) > > Any reason not to put -Wnested-externs in -Wall or -Wextra? >=20 > It warns for any "extern" declaration in other than file scope. This is > completely standard C, and useful as well. >=20 > It is harmful to warn about idiomatic code, especially if there is no real > alternative. >=20 > I don't think anyone will accidentally do this either (you don't type > "extern" if you don't mean it, after all). >=20 > Do you have any example where this warning helped you find a bug? It may have been idiomatic 30 years ago, but it isn't any longer. And there= 's an easy alternative: just move the declaration out of the function and up to file scope. It makes more sense that way and looks better. Or, better yet, include the proper header file for the extern declaration. Most instances I= 've seen of the warning have been stuff like people putting "extern int errno" inside of a function instead of realizing that they're supposed to just do #include instead (possibly because the code is from before the he= ader was standardized?). In the errno case it's particularly harmful because err= no may be defined as a macro that's incompatible with the declaration being us= ed.=