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

John McCall rjmccall at apple.com
Thu Jul 30 07:54:10 PDT 2009


Erik Verbruggen wrote:
> 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?
>   

You could keep a set of caught types and just walk the caught class's 
inheritance hierarchy whenever you reach a new clause.  That's O(cb), 
where /c/ is the number of catch clauses and /b/ is total number of base 
classes a class has.  I think there are a lot of other things that 
implicitly scale with /b/.

But I don't think the quadratic/linear difference is particularly 
important here, where /c/ is very unlikely to get large.

John.



More information about the cfe-dev mailing list