IncludeChecker is based on a simple principle: only include what you need. To determine if a source file is actually needing something from a header file, ctags is used. Ctags is used to generate a list of all tags (classes, structs, typedefs, functions etc.) that are declared within a source file. Simple regular expressions are then used to check each tag to see if it's being used in the source file. If none of the tags of a header are used in the source file, the header file is regarded as being unused.
Because IncludeChecker does not completely parse a source file like the compiler does, it will miss certain unused includes, or incorrectly regard some includes as unused. The latter can be fixed by adding exclude paths or ignored headers, see Command line options or Configuration XML.
These constructs are not supported by IncludeChecker:
#include MYHEADER
. IncludeChecker has no way of finding out which header is included by such a statement.#define START_CLASS(x) class x: public Object
. In the header the class declaration will start with START_CLASS(MyClass)
and ctags has no way of knowing that it's in fact a class declaration. Therefor it will not find MyClass as a tag, and IncludeChecker may regard the header file containing MyClass as unused, even when it is using MyClass.