Bug 43728 - Add warning for redundant static function prototypes
Summary: Add warning for redundant static function prototypes
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 36195 (view as bug list)
Depends on:
Blocks: new-warning, new_warning
  Show dependency treegraph
 
Reported: 2010-04-12 15:06 UTC by Jakub Jelinek
Modified: 2019-04-28 23:00 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-07-25 00:00:00


Attachments
gcc46-pr43728.patch (872 bytes, patch)
2010-04-12 15:14 UTC, Jakub Jelinek
Details | Diff
gcc46-pr43728.patch (1.86 KB, patch)
2010-04-14 16:06 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2010-04-12 15:06:14 UTC
Prototypes for static functions that aren't used in between the prototype and
the actual static function definition are useless and could be cleaned up, I think gcc itself has thousands of such useless prototypes.

It isn't hard to add a warning for this.  Given:
static void foo (int);

#ifdef D
void bar (void)
{
  foo (0);
}
#endif

static void foo (int x)
{
  x++;
}

void baz (void)
{
  foo (0);
}

we'd warn about the foo prototype (unless compiling with -DD).
Comment 1 Jakub Jelinek 2010-04-12 15:14:52 UTC
Created attachment 20367 [details]
gcc46-pr43728.patch

Quick patch, so far without documentation and testsuite and almost untested.
Comment 2 Jakub Jelinek 2010-04-12 15:16:31 UTC
*** Bug 36195 has been marked as a duplicate of this bug. ***
Comment 3 Manuel López-Ibáñez 2010-04-12 15:38:08 UTC
If you are going to add such a warning, please be more explicit. I suggest:

"redundant prototype for static function %qD because it is never used before its definition"





Comment 4 Jason Merrill 2010-04-12 16:16:36 UTC
...and then after removing the prototype, compiling with -DD would fail.  I don't object to having such a flag, but I don't think we want it in -Wall.
Comment 5 Jakub Jelinek 2010-04-12 16:29:09 UTC
-Wredundant-decls is a non-default warning already, not enabled with -Wall nor -W and I certainly don't want to enable it by default.
Comment 6 Jakub Jelinek 2010-04-14 16:06:27 UTC
Created attachment 20378 [details]
gcc46-pr43728.patch

Updated patch.  There are still cases I'm unsure about.  E.g. for:

static void g ();

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

void g()
{
}

int main () {
  f ();
}

with -Wredundant-decls=2 in C we complain (even with -Wredundant-decls alone and before the patch) that void g(); in f function is redundant declaration, but in C++ we don't and instead with -Wredundant-decls=2 the warning newly diagnoses
the first static void g (); prototype as redundant (in this case it isn't, because it affects whether void g (); in the subroutine is static or not).
Not sure why TREE_USED isn't set in C++ case during the g call in f, Jason?
Comment 7 Jason Merrill 2010-04-14 20:26:18 UTC
Presumably TREE_USED isn't set on the global declaration because the call uses the local one.  And the local declaration might not be redundant if the programmer is using it to suppress argument-dependent lookup.
Comment 8 Eric Gallager 2017-07-25 18:38:24 UTC
Confirmed, although I probably wouldn't use such a warning myself if it were added. (I like redundancy)
Comment 9 Eric Gallager 2018-07-27 19:26:24 UTC
(In reply to Eric Gallager from comment #8)
> Confirmed, although I probably wouldn't use such a warning myself if it were
> added. (I like redundancy)

Do people still want this? Putting in WAITING for someone to re-confirm.
Comment 10 Eric Gallager 2019-04-28 23:00:45 UTC
(In reply to Eric Gallager from comment #9)
> (In reply to Eric Gallager from comment #8)
> > Confirmed, although I probably wouldn't use such a warning myself if it were
> > added. (I like redundancy)
> 
> Do people still want this? Putting in WAITING for someone to re-confirm.

No reply, I guess no one really wants this after all.