public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "egallager at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-87656-4-et74Ob18iW@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-87656-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87656

--- Comment #10 from Eric Gallager <egallager at gcc dot gnu.org> ---
(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?
> 
> It warns for any "extern" declaration in other than file scope.  This is
> completely standard C, and useful as well.
> 
> It is harmful to warn about idiomatic code, especially if there is no real
> alternative.
> 
> I don't think anyone will accidentally do this either (you don't type
> "extern" if you don't mean it, after all).
> 
> 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 <errno.h> instead (possibly because the code is from before the header
was standardized?). In the errno case it's particularly harmful because errno
may be defined as a macro that's incompatible with the declaration being used.

  parent reply	other threads:[~2021-12-10  5:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-87656-4@http.gcc.gnu.org/bugzilla/>
2021-10-26  8:39 ` dcb314 at hotmail dot com
2021-11-13 21:49 ` egallager at gcc dot gnu.org
2021-11-14 12:53 ` segher at gcc dot gnu.org
2021-12-10  5:55 ` egallager at gcc dot gnu.org [this message]
2022-04-27 10:25 ` dcb314 at hotmail dot com
2022-04-28 16:56 ` segher at gcc dot gnu.org
2022-04-28 17:49 ` schwab@linux-m68k.org
2022-04-28 22:47 ` egallager at gcc dot gnu.org
2022-04-29  9:19 ` dcb314 at hotmail dot com
2022-04-29  9:50 ` jakub at gcc dot gnu.org
2022-06-03 10:51 ` segher at gcc dot gnu.org
2022-06-08  0:50 ` egallager at gcc dot gnu.org
2022-06-24 22:28 ` jason at gcc dot gnu.org
2023-02-10 13:29 ` tschwinge at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-87656-4-et74Ob18iW@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).