Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>DISCLAIMER:</strong> My day job is working for a company that develops static analysis tools.</p> <p>I would be surprised if most (if not all) static analysis tools did not have some form of header usage check. You could use <a href="http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis" rel="noreferrer">this</a> wikipedia page to get a list of available tools and then email the companies to ask them.</p> <p>Some points you might consider when you're evaluating a tool:</p> <p>For function overloads, you want all headers containing overloads to be visible, not just the header that contains the function that was selected by overload resolution:</p> <pre><code>// f1.h void foo (char); // f2.h void foo (int); // bar.cc #include "f1.h" #include "f2.h" int main () { foo (0); // Calls 'foo(int)' but all functions were in overload set } </code></pre> <p>If you take the brute force approach, first remove all headers and then re-add them until it compiles, if 'f1.h' is added first then the code will compile but the semantics of the program have been changed.</p> <p>A similar rule applies when you have partial and specializations. It doesn't matter if the specialization is selected or not, you need to make sure that all specializations are visible:</p> <pre><code>// f1.h template &lt;typename T&gt; void foo (T); // f2.h template &lt;&gt; void foo (int); // bar.cc #include "f1.h" #include "f2.h" int main () { foo (0); // Calls specialization 'foo&lt;int&gt;(int)' } </code></pre> <p>As for the overload example, the brute force approach may result in a program which still compiles but has different behaviour.</p> <p>Another related type of analysis that you can look out for is checking if types can be forward declared. Consider the following:</p> <pre><code>// A.h class A { }; // foo.h #include "A.h" void foo (A const &amp;); // bar.cc #include "foo.h" void bar (A const &amp; a) { foo (a); } </code></pre> <p>In the above example, the definition of 'A' is not required, and so the header file 'foo.h' can be changed so that it has a forward declaration only for 'A':</p> <pre><code>// foo.h class A; void foo (A const &amp;); </code></pre> <p>This kind of check also reduces header dependencies.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload