Helper script "cleanFwdDecl.sh" attached.
As explained in it:
# Quick and dirty script to help removing useless class and struct
# forward declarations in header files.
#
# Typical usage:
# $ cleanFwdDecl.sh $(find content/ -name *.h)
#
# What this script does:
# - look for lines looking like "class xxx;" or "struct xxx;"
# - if word xxx is found only once in the file, remove the whole line
# containing this word
#
# What this script does NOT:
# - take care of style (removing extra empty line, removing namespace
# becoming obsolete after deleting forward declarations, ...)
# - handle templates properly, e.g. :
# template <typename T>
# class UselessForwardDecl;
# - many other things I don't know yet :-)
> This may be an interesting presubmit.
Agreed. However, I'm not sure how to proceed to perform a reliable check here.
To me the check should only fail if removed lines from files in a given patch set lead to new useless forward declarations in those files.
can you explain how you create these CLs? Do you use some tools to identify missing / unnecessary declarations?
Also, can you explain the motivation for cleaning this up?
> can you explain how you create these CLs? Do you use some tools to identify missing / unnecessary declarations?
Sure, I first use a homemade-quick-and-dirty script (available in Comment 4 of this bug : https://bugs.chromium.org/p/chromium/issues/detail?id=662195#c4) to detect and remove what is very likely to be useless class and struct forward declarations.
Then I manually fix style (remove extra empty lines, remove namespace scopes becoming obsolete after removal etc ..) and submit a CL.
I make different CLs for different parts of Chromium to avoid huge code reviews and limit conflicts.
> Also, can you explain the motivation for cleaning this up?
Besides the source cleaning itself, the main reason is that I often use grep to browse code, especially "git grep <classname>". In that case useless forward declarations are adding matches that are useless to me.
Feel free to ping me in IRC for further details :)
> I'm worried that we're only temporarily fixing this problem, so as robliao@ already suggested, please add a presubmit check.
Agreed. I've just uploaded a CL for this: https://codereview.chromium.org/2525263002/
Comment 1 by bugdroid1@chromium.org
, Nov 4 2016