public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50477] New: -Wunused-parameter should not warn about virtual method declarations with bodies
@ 2011-09-22  6:40 miles at gnu dot org
  2011-09-22 22:05 ` [Bug c++/50477] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: miles at gnu dot org @ 2011-09-22  6:40 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50477
           Summary: -Wunused-parameter should not warn about virtual
                    method declarations with bodies
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: trivial
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: miles@gnu.org


In the following code:

   struct X { virtual void f (int a) { } };

One gets a warning from -Wunused-parameter, "unused parameter 'a'".

While this is understandable, I think it's undesirable -- clearly the parameter
'a' will often be used by overrides of X::f, and the parameter name 'a' serves
a valuable documentation purpose here, even if it's not strictly required.

The basic problem of course, is that in this case, f is both a virtual method
declaration which covers overriding methods as well, and a definition of X's
definition of it.

One can avoid this by defining X::f outside the class definition, but for
trivial definitions like the above, this would seem like annoying make-work if
done only to shut up -Wunused-parameter.

My current method of avoiding the warning is to comment out the parameter name: 

   virtual void f (int /* a */) { }

but this again seems like an annoying wart, rather than natural code -- it's
both less readable (especially when the parameter has a funny type like a
function pointer) and yields a slightly confusing inconsistency ("why do
comment-out some method parameter names but not others?!" "oh it's just to shut
up -Wunused-parameter... :(").

Anyway, the current behavior seems wrong to me; I think -Wunused-parameter
shoul d stay silent for method virtual definitions inside the class definition.

[If this were a very rare scenario, I suppose I wouldn't care about the need to
work around it, but it seems to happen all the time for me...]

Thanks,

-Miles


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

end of thread, other threads:[~2013-05-15  5:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-22  6:40 [Bug c++/50477] New: -Wunused-parameter should not warn about virtual method declarations with bodies miles at gnu dot org
2011-09-22 22:05 ` [Bug c++/50477] " pinskia at gcc dot gnu.org
2011-09-22 22:38 ` miles at gnu dot org
2011-09-23  9:00 ` jakub at gcc dot gnu.org
2011-09-23 10:00 ` miles at gnu dot org
2012-05-24 15:39 ` paolo.carlini at oracle dot com
2012-05-24 19:52 ` jason at gcc dot gnu.org
2013-05-15  5:54 ` anthony.foiani at gmail dot com

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