From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11983 invoked by alias); 22 Sep 2011 22:34:54 -0000 Received: (qmail 10494 invoked by uid 22791); 22 Sep 2011 22:34:51 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 22 Sep 2011 22:34:37 +0000 From: "miles at gnu dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/50477] -Wunused-parameter should not warn about virtual method declarations with bodies Date: Thu, 22 Sep 2011 22:38:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: trivial X-Bugzilla-Who: miles at gnu dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-09/txt/msg01602.txt.bz2 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...]