public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/43728]  New: Warning for redundant static function prototypes
@ 2010-04-12 15:06 jakub at gcc dot gnu dot org
  2010-04-12 15:15 ` [Bug c/43728] " jakub at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-04-12 15:06 UTC (permalink / raw)
  To: gcc-bugs

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).


-- 
           Summary: Warning for redundant static function prototypes
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jakub at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43728


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

* [Bug c/43728] Warning for redundant static function prototypes
  2010-04-12 15:06 [Bug c/43728] New: Warning for redundant static function prototypes jakub at gcc dot gnu dot org
@ 2010-04-12 15:15 ` jakub at gcc dot gnu dot org
  2010-04-12 15:16 ` jakub at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-04-12 15:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from jakub at gcc dot gnu dot org  2010-04-12 15:14 -------
Created an attachment (id=20367)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20367&action=view)
gcc46-pr43728.patch

Quick patch, so far without documentation and testsuite and almost untested.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43728


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

* [Bug c/43728] Warning for redundant static function prototypes
  2010-04-12 15:06 [Bug c/43728] New: Warning for redundant static function prototypes jakub at gcc dot gnu dot org
  2010-04-12 15:15 ` [Bug c/43728] " jakub at gcc dot gnu dot org
@ 2010-04-12 15:16 ` jakub at gcc dot gnu dot org
  2010-04-12 15:38 ` manu at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-04-12 15:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jakub at gcc dot gnu dot org  2010-04-12 15:16 -------
*** Bug 36195 has been marked as a duplicate of this bug. ***


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eugene dot zelenko at gmail
                   |                            |dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43728


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

* [Bug c/43728] Warning for redundant static function prototypes
  2010-04-12 15:06 [Bug c/43728] New: Warning for redundant static function prototypes jakub at gcc dot gnu dot org
  2010-04-12 15:15 ` [Bug c/43728] " jakub at gcc dot gnu dot org
  2010-04-12 15:16 ` jakub at gcc dot gnu dot org
@ 2010-04-12 15:38 ` manu at gcc dot gnu dot org
  2010-04-12 16:17 ` jason at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-04-12 15:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from manu at gcc dot gnu dot org  2010-04-12 15:38 -------
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"


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43728


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

* [Bug c/43728] Warning for redundant static function prototypes
  2010-04-12 15:06 [Bug c/43728] New: Warning for redundant static function prototypes jakub at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2010-04-12 15:38 ` manu at gcc dot gnu dot org
@ 2010-04-12 16:17 ` jason at gcc dot gnu dot org
  2010-04-12 16:29 ` jakub at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-04-12 16:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jason at gcc dot gnu dot org  2010-04-12 16:16 -------
...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.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43728


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

* [Bug c/43728] Warning for redundant static function prototypes
  2010-04-12 15:06 [Bug c/43728] New: Warning for redundant static function prototypes jakub at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2010-04-12 16:17 ` jason at gcc dot gnu dot org
@ 2010-04-12 16:29 ` jakub at gcc dot gnu dot org
  2010-04-14 16:06 ` jakub at gcc dot gnu dot org
  2010-04-14 20:26 ` jason at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-04-12 16:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jakub at gcc dot gnu dot org  2010-04-12 16:29 -------
-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.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43728


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

* [Bug c/43728] Warning for redundant static function prototypes
  2010-04-12 15:06 [Bug c/43728] New: Warning for redundant static function prototypes jakub at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2010-04-12 16:29 ` jakub at gcc dot gnu dot org
@ 2010-04-14 16:06 ` jakub at gcc dot gnu dot org
  2010-04-14 20:26 ` jason at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-04-14 16:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jakub at gcc dot gnu dot org  2010-04-14 16:06 -------
Created an attachment (id=20378)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20378&action=view)
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?


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #20367|0                           |1
        is obsolete|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43728


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

* [Bug c/43728] Warning for redundant static function prototypes
  2010-04-12 15:06 [Bug c/43728] New: Warning for redundant static function prototypes jakub at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2010-04-14 16:06 ` jakub at gcc dot gnu dot org
@ 2010-04-14 20:26 ` jason at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu dot org @ 2010-04-14 20:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jason at gcc dot gnu dot org  2010-04-14 20:26 -------
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.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43728


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

end of thread, other threads:[~2010-04-14 20:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-12 15:06 [Bug c/43728] New: Warning for redundant static function prototypes jakub at gcc dot gnu dot org
2010-04-12 15:15 ` [Bug c/43728] " jakub at gcc dot gnu dot org
2010-04-12 15:16 ` jakub at gcc dot gnu dot org
2010-04-12 15:38 ` manu at gcc dot gnu dot org
2010-04-12 16:17 ` jason at gcc dot gnu dot org
2010-04-12 16:29 ` jakub at gcc dot gnu dot org
2010-04-14 16:06 ` jakub at gcc dot gnu dot org
2010-04-14 20:26 ` jason at gcc dot gnu dot 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).