<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 12, 2015 at 10:11 AM, Nico Weber <span dir="ltr"><<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.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"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Tue, Aug 11, 2015 at 10:15 PM, Daniel Marjamäki <span dir="ltr"><<a href="mailto:Daniel.Marjamaki@evidente.se" target="_blank">Daniel.Marjamaki@evidente.se</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
ideally there should be no -Wunused-parameter compiler warning when the parameter is used.<br>
<br>
would it feel better to move the "FP" warnings about virtual functions, for instance to clang-tidy?<br>
<span><br>
> If you enable this warning, you probably want to know about unused parameters, independent of if your function is virtual or not, no?<br>
<br>
</span>imho there are some compiler warnings that are too noisy. I don't like to get a warning when there is obviously no bug:<br>
<br>
sign compare:<br>
  if the signed value is obviously not negative then there is no bug:<br>
    signed x;  .. if (x>10 && x < s.size())<br>
unused parameter:<br>
  could check in the current translation unit if the parameter is used in an overloaded method.<br></blockquote><div><br></div></span><div>It doesn't warn about the presence of the parameter, but about the presence of the name. If you say f(int, int) instead of f(int a, int b) then the warning won't fire. </div></div></div></div></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>(And if you don't like this warning, then don't enable it.)</div></div></div></div></blockquote><div><br>This isn't usually the approach we take with Clang's warnings - we try to remove false positives (where "false positive" is usually defined as "diagnoses something which is not a bug" (where bug is defined as "the resulting program behaves in a way that the user doesn't intend/expect")) where practical.<br><br>If the subset of cases where this warning fires on parameters to virtual functions produces more noise (if a significant % of cases just result in commenting out the parameter name rather than removing the parameter) than signal, it's certainly within the realm of discussion that we have about whether that subset of cases is worth keeping in the warning.<br><br>- David<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
constructor initialization order:<br>
  should not warn if the order obviously does not matter. for instance initialization order of pod variables using constants.<br>
etc<br>
<br>
Best regards,<br>
Daniel Marjamäki<br>
<br>
..................................................................................................................<br>
Daniel Marjamäki Senior Engineer<br>
Evidente ES East AB  Warfvinges väg 34  SE-112 51 Stockholm  Sweden<br>
<br>
Mobile:                 <a href="tel:%2B46%20%280%29709%2012%2042%2062" value="+46709124262" target="_blank">+46 (0)709 12 42 62</a><br>
E-mail:                 <a href="mailto:Daniel.Marjamaki@evidente.se" target="_blank">Daniel.Marjamaki@evidente.se</a><br>
<br>
<a href="http://www.evidente.se" rel="noreferrer" target="_blank">www.evidente.se</a><br>
<br>
________________________________________<br>
Från: <a href="mailto:thakis@google.com" target="_blank">thakis@google.com</a> [<a href="mailto:thakis@google.com" target="_blank">thakis@google.com</a>] f&#246;r Nico Weber [<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>]<br>
Skickat: den 11 augusti 2015 20:50<br>
Till: David Blaikie<br>
Kopia: <a href="mailto:reviews%2BD11940%2Bpublic%2B578c1335b27aa98b@reviews.llvm.org" target="_blank">reviews+D11940+public+578c1335b27aa98b@reviews.llvm.org</a>; Daniel Marjamäki; <a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
Ämne: Re: [PATCH] D11940: don't diagnose -Wunused-parameter in virtual method or method that overrides base class method<br>
<br>
On Tue, Aug 11, 2015 at 11:32 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a><mailto:<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>>> wrote:<br>
<span><br>
<br>
On Tue, Aug 11, 2015 at 8:46 AM, Nico Weber via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>>> wrote:<br>
Can't you just change your signature to<br>
<br>
  virtual void a(int /* x */) {}<br>
<br>
in these cases?<br>
<br>
You could - does it add much value to do that, though?<br>
<br>
If you enable this warning, you probably want to know about unused parameters, independent of if your function is virtual or not, no?<br>
<br>
(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<br>
<br>
<br>
</span><div><div>On Tue, Aug 11, 2015 at 6:43 AM, Daniel Marjamäki <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>>> wrote:<br>
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>
_______________________________________________<br>
cfe-commits mailing list<br>
</div></div><a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>><br>
<span><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>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
</span><a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><mailto:<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>
<br>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>