Hi Dave, all,
Attached is a cppadditions.patch (against recent git head of
gcc-python-plugin) that adds a number of attributes to various gcc.Tree
classes, mainly relevant for C++. It is surely far from polished and
there's probably some issues with it. Anyway, let me know what you
think about it.
* I added c_string_quote because of problems with quotes (") in docu
strings (where I shamelessly reused the documentation present in GCC's
tree.h and cp-tree.h, and that already contained those quotes). The
implementation of that function is surely evidence that I am no native
Python programmer... ;)
* I needed to add cu.add_include("cp/cp-tree.h") to generate-tree-c.py
-- not sure if that is acceptable (it would fail for GCC installations
that do not include C++ support).
I made those additions to be able to write the attached
unusedparameters.py, which I used to find unused function parameters in
the LibreOffice code base: When we made that 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). The script 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).
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)) in the LibreOffice
source code (and let unusedparameters.py ignore those). One problem I
found with that is that for constructors (and only for constructors),
the annotation needs to go into the constructor's declaration instead of
the definition, for unusedparameters.py to find it within
arg.attributes. That is,
class C { C(int); };
C::C(__attribute__ ((unused)) int) {}
causes unusedparameters.py to erroneously warn about the int parameter,
while
class C { C(__attribute__ ((unused)) int); };
C::C(int) {}
has the desired effect.
Does anybody happen to know whether that is a problem of GCC itself (I
observed it with Fedora 16's gcc-c++-4.6.2-1.fc16.x86_64) or of
gcc-python-plugin?
Stephan