[PATCH] Static analysis checker for catch handler inversion

Aaron Ballman aaron at aaronballman.com
Mon Oct 27 15:30:21 PDT 2014


It is possible to write catch handlers such that they never execute
due to inversion of the class hierarchy, such as:

class B {};
class D : public B {};

void f() {
  try {
    // ...
  } catch (B &b) {
    // ...
  } catch (D &d) {
    // ...
  }
}

This patch causes a static analysis warning to be generated for code
where a catch handler cannot execute due to class hierarchy inversion
with regards to other catch handlers for the same try block.

This issue is covered by CERT's secure coding rule:
https://www.securecoding.cert.org/confluence/display/cplusplus/ERR36-CPP.+Catch+handlers+should+order+their+parameter+types+from+most+derived+to+least+derived

It's also covered by MISRA rule 15-3-6.

~Aaron
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CatchHandlerChecker.patch
Type: application/octet-stream
Size: 6096 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141027/234c611b/attachment.obj>


More information about the cfe-commits mailing list