<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 11, 2015 at 8:46 AM, Nico Weber via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Can't you just change your signature to<div><br></div><div><span style="font-size:12.8000001907349px"> virtual void a(int /* x */) {}</span><br style="font-size:12.8000001907349px"></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">in these cases?</span></div></div></blockquote><div><br></div><div>You could - does it add much value to do that, though? (perhaps it does - it means you express the intent that the parameter is not used and the compiler helps you check that (so that for the parameters you think /should/ be used (you haven't commented out their name but accidentally shadow or otherwise fail to reference, you still get a warning))<br><br>- David</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Tue, Aug 11, 2015 at 6:43 AM, Daniel Marjamäki <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">danielmarjamaki created this revision.<br>
danielmarjamaki added a reviewer: krememek.<br>
danielmarjamaki added a subscriber: cfe-commits.<br>
<br>
Don't diagnose -Wunused-parameter in methods that override other methods because the overridden methods might use the parameter<br>
<br>
Don't diagnose -Wunused-parameter in virtual methods because these might be overriden by other methods that use the parameter.<br>
<br>
Such diagnostics could be more accurately written if they are based on whole-program-analysis that establish if such parameter is unused in all methods.<br>
<br>
<br>
<br>
<a href="http://reviews.llvm.org/D11940" rel="noreferrer" target="_blank">http://reviews.llvm.org/D11940</a><br>
<br>
Files:<br>
lib/Sema/SemaDecl.cpp<br>
test/SemaCXX/warn-unused-parameters.cpp<br>
<br>
Index: test/SemaCXX/warn-unused-parameters.cpp<br>
===================================================================<br>
--- test/SemaCXX/warn-unused-parameters.cpp<br>
+++ test/SemaCXX/warn-unused-parameters.cpp<br>
@@ -32,3 +32,20 @@<br>
auto l = [&t...]() { return sizeof...(s); };<br>
return l();<br>
}<br>
+<br>
+// Don't diagnose virtual methods or methods that override base class<br>
+// methods.<br>
+class Base {<br>
+public:<br>
+ virtual void f(int x);<br>
+};<br>
+<br>
+class Derived : public Base {<br>
+public:<br>
+ // Don't warn in overridden methods.<br>
+ virtual void f(int x) {}<br>
+<br>
+ // Don't warn in virtual methods.<br>
+ virtual void a(int x) {}<br>
+};<br>
+<br>
Index: lib/Sema/SemaDecl.cpp<br>
===================================================================<br>
--- lib/Sema/SemaDecl.cpp<br>
+++ lib/Sema/SemaDecl.cpp<br>
@@ -10797,8 +10797,13 @@<br>
<br>
if (!FD->isInvalidDecl()) {<br>
// Don't diagnose unused parameters of defaulted or deleted functions.<br>
- if (!FD->isDeleted() && !FD->isDefaulted())<br>
- DiagnoseUnusedParameters(FD->param_begin(), FD->param_end());<br>
+ if (!FD->isDeleted() && !FD->isDefaulted()) {<br>
+ // Don't diagnose unused parameters in virtual methods or<br>
+ // in methods that override base class methods.<br>
+ const auto MD = dyn_cast<CXXMethodDecl>(FD);<br>
+ if (!MD || (MD->size_overridden_methods() == 0U && !MD->isVirtual()))<br>
+ DiagnoseUnusedParameters(FD->param_begin(), FD->param_end());<br>
+ }<br>
DiagnoseSizeOfParametersAndReturnValue(FD->param_begin(), FD->param_end(),<br>
FD->getReturnType(), FD);<br>
<br>
<br>
<br>
<br></div></div>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div></div>