pukkaone edited this page Oct 14, 2011 · 7 revisions
Clone this wiki locally

Find Unnecessary Includes

Given a C++ translation unit that compiles without errors, this tool lists unnecessary #include directives in the main source file. Nested #include directives in the files included from the main source file are not considered.

Unnecessary #include directives

Definition: An #include directive is unnecessary if the translation unit compiles without errors after you remove it.

Replaceable #include directives

Definition: An #include directive is replaceable if it can be replaced with one or more #include directives for different headers without causing a compile error.

For example, suppose the header file Base.h defines a base class. The header file Derived.h defines a class deriving from the base class, so it includes Base.h. The main source file includes Derived.h but does not use any symbols defined in Derived.h and uses only symbols defined in Base.h. The tool will say Derived.h is replaceable, and suggest the main source file directly include Base.h instead.