I’ve just came up with an idea to solve a problem and wanted to share it. Sorry if too banal.
So, a big C++ project I am reviewing, contains many includes which relies on symbols from other includes but which don’t include the required includes. Any slight change in build-procedure results in “missing symbol” failures.
So in order to check all includes for self-containment at once, I search for all *.h, create on the fly a cpp-file which only contains #include -statement with this .h file and try to compile it. At the end I obtain a list of “good” and “bad” include files.
Cool isn’t it 🙂
Or is there an easier solution to do it?
If every .cpp file includes it’s own header-file first, and then other headers, you’ll get this check without using external tools.
This is actually part of Googles C++ Style Guide for the same reason:
If you have any header files that does not have a corresponding .cpp-file, you’d have to do something special for them.