<font face="Menlo">I'd like to have the following tools to help with static analysis & code coverage:</font><div><font face="Menlo"><br></font></div><div><font face="Menlo">1) test whether code is reachable or not. </font></div>
<div><font face="Menlo"><br></font></div><div><font face="Menlo">Of course it only works for executables and may have some caveats (eg: goto), but its still useful diagnostic tool.<br></font><div><br></div><div>__traits(isReachable): true when the current context can be reached via at least one code path starting from main():</div>
<div><br></div><div>----</div><div>void fun1(){</div><div>//__traits(isReachable) would be false here because even though fun1 is called by fun2, it can never be called starting from main().</div><div>}</div><div>void fun2(){fun1;}</div>
<div>void fun3(){} // would also be false, because of static if(temp); with temp being known to be 0 at compile time.</div><div>void fun4(){</div><div>return;</div><div>//__traits(isReachable) would be false here because all code paths return above this point.</div>
<div>}</div><div>void main(){enum temp=0; static if(temp) fun3; fun4;}</div><div><div>----</div></div><div><br></div><div>When a pointer to a function is taken, we may want to assume by convention that __traits(isReachable) is true.</div>
<div><br></div><div>This would enable for example to make sure a given code is never called. Note, static assert(0) is not the same.</div><div><br></div><div>2)</div><div>static code call graph: know caller/calling functions for a given function.</div>
<div><br></div></div><div><font face="Menlo"><span style="color:#444444"><br></span></font></div><div><font face="Menlo"><span style="color:#444444">3) static code coverage</span></font></div><div><font face="Menlo"><span style="color:#444444">this would allow us to tell at compile time the code coverage of a module; it is larger than runtime coverage, but still useful to find dead code.</span></font></div>
<div><font face="Menlo"><span style="color:#444444"><br></span></font></div><div><font face="Menlo"><span style="color:#444444"><br></span></font></div><div><font face="Menlo"><span style="color:#444444"><br></span></font></div>
<div><font face="Menlo"><span style="color:#444444"><br></span></font></div>