[cfe-dev] Exception Specs & Redeclarations

Sebastian Redl sebastian.redl at getdesigned.at
Sun Mar 6 03:54:45 PST 2011


Hi,

C++0x says that exception specs on redeclarations no longer have to be equivalent, just compatible. It also has the interesting rule that noexcept(false) is compatible with any non-empty throw() spec. This is a bit problematic for Clang's redeclaration checking. Consider:

void f() throw(A);
void f() noexcept(false); // compatible with first decl
void f() throw(B); // compatible with second decl, incompatible with first

Because we always do redecl checking against the latest decl (and if I'm wrong about that, just flip the first two decls), this problem would not be detected unless I adjust the spec of the second decl to match the first when merging. Now, I can do that (I just have to rebuild the function type from scratch), but there's an interesting problem here for the dependent case:

template <bool Throws>
void g() throw(A);
template <bool Nothrow>
void g() noexcept(Nothrow);

Here I can't remove the noexcept spec, because I still need it to determine that g<true> is actually an invalid instantiation, because the prototypes then conflict.

My opinion is that the standard is broken here. noexcept(false) shouldn't be compatible with throw(X) specifiers. That can only lead to chaos.

But if there are important reasons to keep the standard as it is, what would be the best way to implement this?

Sebastian



More information about the cfe-dev mailing list