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: unassig...@gcc.gnu.org ReportedBy: mi...@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