[cfe-dev] Applicability of -Wunused-param
Stephan Bergmann via cfe-dev
cfe-dev at lists.llvm.org
Tue Sep 18 00:40:08 PDT 2018
On 18/09/2018 03:40, George Karpenkov via cfe-dev wrote:
> Many projects, including LLVM have to turn -Wunused-param off, as it has too many false positives.
>
> Most false positives stem from the fact that often a function has to take a parameter not because it wants to, but because:
>
> 1. It’s part of an interface, and has to be API/ABI compatible
> 2. It overrides another function which does need that parameter
>
> However, this warning is still very useful when the function is:
>
> - static
> - private
> - in an anonymous namespace
>
> This asks for a warning on unused parameters which is restricted to “private" (static local / etc) functions.
But the criteria 1/2 whether a function needs to have unused parameters
are orthogonal to whether the function is "private" (per your vague
notion of what that would mean). For example, a pointer to a static
function can be passed to an API that expects a certain function type.
(At least for C++, an approach to suppress false -Wunused-param is to
leave the parameters that are unused per criteria 1/2 unnamed in the
function definition. But which of course doesn't catch cases where the
parameter has been left unnamed "maliciously" and a -Wunused-param would
be warranted.)
More information about the cfe-dev
mailing list