<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Oct 27, 2014 at 4:35 PM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Mon, Oct 27, 2014 at 7:30 PM, Jordan Rose <<a href="mailto:jordan_rose@apple.com">jordan_rose@apple.com</a>> wrote:<br>
> Nifty! But do you think this is cheap enough for a general compiler warning? It certainly doesn't depend on the analyzer's path-sensitive analysis, so it's mostly just how much we care about the cost of isDerivedFrom.<br>
<br>
</span>This should be relatively inexpensive, so it may make sense as a<br>
general compiler warning if others feel that's a better approach.<br></blockquote><div><br></div><div>Yes, I think this is a good candidate for an (on-by-default) compiler warning.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks!<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5">><br>
> Jordan<br>
><br>
><br>
>> On Oct 27, 2014, at 15:30, Aaron Ballman <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>> wrote:<br>
>><br>
>> It is possible to write catch handlers such that they never execute<br>
>> due to inversion of the class hierarchy, such as:<br>
>><br>
>> class B {};<br>
>> class D : public B {};<br>
>><br>
>> void f() {<br>
>>  try {<br>
>>    // ...<br>
>>  } catch (B &b) {<br>
>>    // ...<br>
>>  } catch (D &d) {<br>
>>    // ...<br>
>>  }<br>
>> }<br>
>><br>
>> This patch causes a static analysis warning to be generated for code<br>
>> where a catch handler cannot execute due to class hierarchy inversion<br>
>> with regards to other catch handlers for the same try block.<br>
>><br>
>> This issue is covered by CERT's secure coding rule:<br>
>> <a href="https://www.securecoding.cert.org/confluence/display/cplusplus/ERR36-CPP.+Catch+handlers+should+order+their+parameter+types+from+most+derived+to+least+derived" target="_blank">https://www.securecoding.cert.org/confluence/display/cplusplus/ERR36-CPP.+Catch+handlers+should+order+their+parameter+types+from+most+derived+to+least+derived</a><br>
>><br>
>> It's also covered by MISRA rule 15-3-6.<br>
>><br>
>> ~Aaron<br>
>> <CatchHandlerChecker.patch><br>
><br>
</div></div></blockquote></div><br></div></div>