TITLE: exception specifications and typedef (Newsgroups: comp.std.c++) PROBLEM: Jack Reeves Can anyone explain why the DWP explicity disallows exception specifications on a typedef? RESPONSE: Paul D. DeRocco Because it's not part of the type. And a good thing too, since exception specs are far more likely to change in a library routine than the actual arg and return types. RESPONSE: smeyers@teleport.com (Scott Meyers), 30 Apr 96 Exception specs may not technically be part of a function's type, but note that they are checked in many cases. From DWP 15.4: 2 If any declaration of a function has an exception-specification, all declarations, including the definition, of that function shall have an exception-specification with the same set of type-ids. If a virtual function has an exception-specification, all declarations, including the definition, of any function that overrides that virtual function in any derived class shall have an exception-specification at least as restrictive as that in the base class. [Example: struct B { virtual void f() throw (int, double); virtual void g(); }; struct D: B { void f(); // ill-formed void g() throw (int); // OK }; --end example] The declaration of D::f is ill-formed because it allows all exceptions, whereas B::f allows only int and double. Simi- larly, any function or pointer to function assigned to, or initializ- ing, a pointer to function shall have an exception-specification at least as restrictive as that of the pointer or function being assigned to or initialized. [Example: void (*pf1)(); // no exception specification void (*pf2) throw(A); void f() { pf1 = pf2; // ok: pf1 is less restrictive pf2 = pf1; // error: pf2 is more restrictive } --end example] 3 In such an assignment or initialization, exception-specifications on return types and parameter types shall match exactly. 4 In other assignments or initializations, exception-specifications shall match exactly. Given that the syntax of function pointers is one of the best arguments for typedefs and given that exception specs are checked during initialization and assignment of function pointers, the explicit restriction against the use of exception specs in typedefs seems almost cruel. Unless there is a better argument against allowing exception specs in typedefs, I think the prohibition should be reconsidered.