[Libreoffice] unused function parameters

Stephan Bergmann sbergman at redhat.com
Tue Jan 24 03:04:33 PST 2012

When we made the original OOo code base warning-clean a number of years 
ago, many warnings about unused parameters were silenced by removing the 
parameter name, instead of actually fixing the code by dropping the 
unused parameter.  Of course, dropping an unused parameter is not always 
the right fix, e.g., in virtual functions (where some overrides require 
the parameter and others don't, so it consistently needs to be present 
in all overrides).

That gave me the idea of writing a GCC plugin (as a gcc-python-plugin 
script, see <https://fedorahosted.org/gcc-python-plugin/>) that looks 
for unused, unnamed parameters (so that they can be revisited now, 
deciding on a proper fix), but takes into account patterns where the 
parameter is likely legitimately unused (like in the case of virtual 
functions).  (In turn, I wrote that script mainly to have something to 
present as <http://fosdem.org/2012/schedule/event/libocompiler> 
"Analysing LibreOffice with Compiler plugins.")

However, there are still a number of legitimately unused function 
parameters that the script does not catch (think about functions that 
need to adhere to a certain signature, so their addresses can be 
assigned to function pointers of given type).  So I started to annotate 
those cases with GCC's __attribute__ ((unused)), wrapped in a newly 
introduced SAL_UNUSED_PARAMETER (sal/types.h), in the LO source code 
(and let the script ignore those).  Unfortunately, I also needed to add 
__attribute__ ((unused)) annotations to a number of headers from 
external modules included in the LO code base (I did that with specific 
new patches that are only relevant when running the plugin script, and 
are only applied to the external source when building with GCC).

The work turned out to be more tedious than anticipated, with many 
legitimately unused parameters having to be annotated, and not that many 
spectacular cases where removing a truly unused parameter has a rippling 
effect of allowing to also remove sizeable chunks of code that supplied 
values for that parameter in calls of the given function.  Anyway, I 
carried along up into somewhere in svl, the result is 
"Removed some unused parameters; added SAL_UNUSED_PARAMETER."  Maybe 
carrying this further up into the higher modules will lead to more 
satisfying results...  I'll see if I can extract an easy hack from this.

So, just in case you stumble across a newly introduced 
SAL_UNUSED_PARAMETER, you know what it is there for.  The GCC plugin 
script itself is detailed at 
"Additions for C++."


More information about the LibreOffice mailing list