<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p><br>
</p>
<br>
<div class="moz-cite-prefix">On 9/18/18 12:40 AM, David Chisnall via
cfe-dev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:5514A8EB-2B4C-45E8-928B-22A73914BAE3@cl.cam.ac.uk">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<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>
</blockquote>
<br>
Might be a good idea to add a fix-it note to the diagnostic to do
this too. I think that would stop a lot of users from disabling it.<br>
<br>
<blockquote type="cite"
cite="mid:5514A8EB-2B4C-45E8-928B-22A73914BAE3@cl.cam.ac.uk">
<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><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"
moz-do-not-send="true">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"
moz-do-not-send="true">cfe-dev@lists.llvm.org</a><br>
<a
href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev"
moz-do-not-send="true">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a></span></font><br>
</blockquote>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>
</blockquote>
<br>
</body>
</html>