title: g++: Is there a way to warn if header file is not included in file?
body: <p>Is there a way to compile source code with <code>g++</code>, and have the compiler warn me if I have not included a file in another file where I should have?</p>
  
  <p>For example, in a large project it is often quite easy to write some code in <code>fileA</code>, which uses another function from <code>fileC</code> (which contains the function declaration), but forget to add the include statement. Such an error can be hidden if <code>fileA</code> also includes another file, <code>fileB</code>, where <code>fileB</code> includes <code>fileC</code>.</p>
  
  <p>This will then compile without error, however if the code is modified at a later date, and we remove the <code>#include fileB.hpp</code> from <code>fileA</code>, then compilation will fail, because we originally forgot to include <code>fileC</code> many months ago!</p>
  
  <p>Is there a compiler switch which will warn us about this problem? Similarly, is there the reverse switch, which will warn us when we <code>#include</code> something which is unnecessary?</p>