[cfe-dev] Exception Specifications

Sebastian Redl sebastian.redl at getdesigned.at
Mon May 18 11:55:50 PDT 2009


Douglas Gregor wrote:
> Hi Sebastian,
>
>
> On May 17, 2009, at 2:42 AM, Sebastian Redl wrote:
>> Also, there is the question of efficient processing of the specs. I have
>> some vague ideas about that involving canonicalization of the spec, but
>> I was wondering if anyone had any experience with that kind of thing.
>
> I'm quite sure I don't understand the issues, here.
>
>     - Doug

Consider:

struct A {};
struct B : A {};
struct C : A {};
struct D : B {};

struct X {};
struct Y :  X {};

void f() throw(Y, D, int, C);
void (*p)() throw(A, A, B, int, X);
p = &f;

The assignment here is valid. But I don't want the check to be quadratic
in the number of declarations, which a naive approach would be. So I
think I need to create a canonical form. In a canonical form, all
redundant declarations are thrown out, so the specs become (Y, int, C)
and (A, int, X). But that doesn't really reduce the problem.
Ideal would be some total ordering of types that allows me to cut off
the search if I know I can't find anything. In this ordering, non-class
types come before class types, and a class type comes after all its base
class types. In the example above, we could end up with (int, Y, C) or
(int, C, Y) for f and (int, A, X) or (int, X, A) for p.
However, that is still not sufficient! I'm still quadratic in the number
of class types. I'm sure there must be some ordering that allows me to
be linear, one that guarantees that I can walk the two specs, never
backtracing on either, and be guaranteed to find base types as I need
them. But I can't think of one.

That's why I asked if anyone knows some trick here.

I'm probably overthinking this. I'd be extremely surprised to find an
exception spec where quadratic performance matters. But ... it's still
quadratic. My soul rebels against writing such code. ;-)

Sebastian



More information about the cfe-dev mailing list