<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><span style="background-color: rgba(255, 255, 255, 0);">It’s worth noting that this warning is very easy to silence and it’s probably better to do that in most cases.  There are two common ways of silencing the warning.</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">Starting with:</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">```</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">int foo(int a, int b)</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">```</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">You can (in all languages) do this:</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">```</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">(void)b;</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">```</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">To indicate that `b` is unused.  Most projects have an `UNUSED` macro to do this.  This improves code readability by indicating that the parameter is intentionally unused in this implementation of the function.  C++ provides a nicer way of doing this and you can just rewrite the function declaration to:</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">```</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">int foo(int a, int)</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">```</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">Now the second parameter exists, but has no name and so is implicitly unused because nothing can possibly refer to it.  This is even easier to read because you know from the first line of the function that this parameter will not be used in the definition.</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">I believe that clang-tidy can perform the latter transformation automatically, though it’s generally a good idea to audit the non-uses of parameters to check that they’re intentional and unavoidable.</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">David </span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span><div></div><font color="#000000"><span style="caret-color: rgb(0, 0, 0); background-color: rgba(255, 255, 255, 0);">On 18 Sep 2018, at 02:40, George Karpenkov via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br><br></span></font></div><blockquote type="cite"><font color="#000000"><span style="caret-color: rgb(0, 0, 0); background-color: rgba(255, 255, 255, 0);">Many projects, including LLVM have to turn -Wunused-param off, as it has too many false positives.<br><br>Most false positives stem from the fact that often a function has to take a parameter not because it wants to, but because:<br><br>1. It’s part of an interface, and has to be API/ABI compatible<br>2. It overrides another function which does need that parameter<br><br>However, this warning is still very useful when the function is:<br><br>- static <br>- private<br>- in an anonymous namespace<br><br>This asks for a warning on unused parameters which is restricted to “private" (static local / etc) functions.<br>Am I missing something there?<br>Has anyone tried to implement such a warning before?<br>_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a></span></font><br></blockquote></body></html>