public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/103104] New: missing warning about superfluous forward declaration -Wsuperfluous-forward-declaration
@ 2021-11-06  0:50 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
  0 siblings, 2 replies; 3+ messages in thread
From: aldot at gcc dot gnu.org @ 2021-11-06  0:50 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103104
           Summary: missing warning about superfluous forward declaration
                    -Wsuperfluous-forward-declaration
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aldot at gcc dot gnu.org
  Target Milestone: ---

It would be nice to have a -Wextra to warn about superfluous forward
declarations.

Random example from gcc/incpath.c
static void add_env_var_paths (const char *, incpath_kind);
static void add_standard_paths (const char *, const char *, const char *, int);
static void free_path (struct cpp_dir *, int);
static void merge_include_chains (const char *, cpp_reader *, int);
static void add_sysroot_to_chain (const char *, int);
static struct cpp_dir *remove_duplicates (cpp_reader *, struct cpp_dir *,
                                          struct cpp_dir *, struct cpp_dir *,
--
static void
free_path (struct cpp_dir *path, int reason)
--
static void
add_env_var_paths (const char *env_var, incpath_kind chain)
--
static void
add_standard_paths (const char *sysroot, const char *iprefix,
--
static struct cpp_dir *
remove_duplicates (cpp_reader *pfile, struct cpp_dir *head,
--
...
All definitions are in topologically correct order, i.e. defined before used,
each and every forward declaration is redundant and error prone.

Maybe there is an existing plugin to that effect?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/103104] missing warning about superfluous forward declaration -Wsuperfluous-forward-declaration
  2021-11-06  0:50 [Bug c/103104] New: missing warning about superfluous forward declaration -Wsuperfluous-forward-declaration aldot at gcc dot gnu.org
@ 2021-11-06  6:30 ` egallager at gcc dot gnu.org
  2021-12-16 23:22 ` msebor at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: egallager at gcc dot gnu.org @ 2021-11-06  6:30 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |egallager at gcc dot gnu.org
           Keywords|                            |diagnostic
             Blocks|                            |87403

--- Comment #1 from Eric Gallager <egallager at gcc dot gnu.org> ---
-Wredundant-decls doesn't catch this?


Referenced Bugs:

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/103104] missing warning about superfluous forward declaration -Wsuperfluous-forward-declaration
  2021-11-06  0:50 [Bug c/103104] New: missing warning about superfluous forward declaration -Wsuperfluous-forward-declaration 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
  1 sibling, 0 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-12-16 23:22 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-16 23:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-06  0:50 [Bug c/103104] New: missing warning about superfluous forward declaration -Wsuperfluous-forward-declaration 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 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).