public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/103104] missing warning about superfluous forward declaration -Wsuperfluous-forward-declaration
Date: Thu, 16 Dec 2021 23:22:10 +0000	[thread overview]
Message-ID: <bug-103104-4-N1ZtaZVuyO@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-103104-4@http.gcc.gnu.org/bugzilla/>

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-12-16
                 CC|                            |msebor at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
             Blocks|87403                       |
     Ever confirmed|0                           |1
           Severity|normal                      |enhancement

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Based on the rather loose(*) description of -Wredundant-decls in the manual:

  Warn if anything is declared more than once in the same scope, even in cases
where multiple declaration is valid and changes nothing. 

I'd expect the warning to trigger but it doesn't, most likely because it only
triggers for the second and subsequent declaration that's not a definition.  It
seems that this can be viewed as a request to enhance -Wredundant-decls to do
what's already documented to do.

Here's a test case:

$ cat a.c && gcc -O2 -S -Wall -Wextra -Wredundant-decls a.c
static void f (void);
static void f (void);      // -Wredundant-decl
static void f (void) { }

static void g (void);      // no warning
static void g (void) { }

void h (void)
{
  f ();
  g ();
}

a.c:2:13: warning: redundant redeclaration of ‘f’ [-Wredundant-decls]
    2 | static void f (void);      // -Wredundant-decl
      |             ^
a.c:1:13: note: previous declaration of ‘f’ with type ‘void(void)’
    1 | static void f (void);
      |             ^

I say "loose" above because it suggests that the following should also be
diagnosed but aren't:

enum E;
enum E;      // missing -Wredundant-decl

struct S;
struct S;    // missing -Wredundant-decl


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403
[Bug 87403] [Meta-bug] Issues that suggest a new warning

      parent reply	other threads:[~2021-12-16 23:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-06  0:50 [Bug c/103104] New: " aldot at gcc dot gnu.org
2021-11-06  6:30 ` [Bug c/103104] " egallager at gcc dot gnu.org
2021-12-16 23:22 ` msebor at gcc dot gnu.org [this message]

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-103104-4-N1ZtaZVuyO@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).