[Bug c++/50477] -Wunused-parameter should not warn about virtual method declarations with bodies

miles at gnu dot org gcc-bugzilla@gcc.gnu.org
Thu Sep 22 22:38:00 GMT 2011


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

--- Comment #2 from miles at gnu dot org 2011-09-22 22:34:01 UTC ---
(In reply to comment #1)
> Having a name vs having correct documentation is the best way.  Also you can
> use the attribute unused in C++ now.

Sorry, I'm not sure I understand your first sentence.  [Of course these methods
also have proper documentation, but that doesn't mean it's OK for the code to
be obfuscated; _both_ should be readable and clear.]

Yeah, you can use an "unused" attribute (or various other methods), but the
problem is that they all uglify the code.  This would be acceptable if it were
a rare case, or one where adding an unused attribute actually provided useful
information -- such as in a _separate_ method definition, where the fact that
the argument is unused is notable.

However my experience is that this case is not rare at all, and in fact, I find
it very common for the root of a class hierarchy to provide trivial/no-op
default definitions for methods that are given more complicated definitions in
subclasses.

Moreover, adding an "unused" attribute actually seems _harmful_ in this case
(in the sense of "confusing"), because it's not just a definition of a
particular class's method body, it's a method declaration that applies to all
the subclasses too.  So if a user sees "attribute ((unused))" next to an
argument in the declaration, a natural question might be "wait, what? am I not
supposed to use this argument in my subclass definitions??"

[If it were a human, a better criteria than just "virtual method with body
defined in class" might include "... and also an obviously trivial definition"
(e.g., {} or {return true;}, etc); but I'm not sure it's reasonable to ask the
compiler to look at that kind of thing...]



More information about the Gcc-bugs mailing list