[cfe-dev] RFC: unreachable catch-clauses due to superclass cathes

AlisdairM(public) public at alisdairm.net
Thu Jul 30 10:33:11 PDT 2009

[Oops, forgot the CC the list again with my reply]

> -----Original Message-----
> From: cfe-dev-bounces at cs.uiuc.edu [mailto:cfe-dev-bounces at cs.uiuc.edu]
> On Behalf Of Erik Verbruggen
> Sent: 30 July 2009 11:35
> To: clang-dev Developers
> Subject: [cfe-dev] RFC: unreachable catch-clauses due to superclass
> cathes
> Hi all,
> After doing duplicate handlers for exceptions in C++, there is still a
> FIXME in Sema::ActOnCXXTryBlock which I am thinking of fixing:
>   // FIXME: We should detect handlers that cannot catch anything
> because an
>   // earlier handler catches a superclass. Need to find a method that
> is not
>   // quadratic for this.
> I pondered a bit on this, and I cannot think of a non-quadratic
> algorithm. So, does anybody have ideas for this?
> I am currently thinking of implementing a quadratic algorithm for it,
> and keep a TODO mentioning that the algorithm should be improved. That
> way, there at least is a check, albeit maybe not the most efficient
> one.

Actually, that FIXME sounds wrong.  An earlier catch handler for a superclass may not trigger due to ambiguity when using multiple inheritance.  Example:

struct base {};

struct a1 : base {};
struct a2 : base {};

struct derived : a1, a2 {};

int main() {
  try {
    throw derived();
  catch( base const &) {} // ambiguous, not selected
  catch( a1 const &) {
    // a1 unambiguously derived from base
    // yet this is the selected catch clause

This might be worth checking in as a perverse test case, but I'm not sure what the protocol for run-time checks in C++ is - all the current tests are syntax-check only as we are not yet generating code for C++.


More information about the cfe-dev mailing list