I've been reading up on GCC internals so that I can begin my project. Initial proposal: http://gcc.gnu.org/ml/gcc/2008-09/msg00383.html (with many follow-ups).
My idea of implementing so far is: Alter the code in gcc/cp/parser.c so that I can check strict exception specification during parsing, similar to how const-ness is enforced (except using warning()). I would store two variables: - A global vector of the exception specification of the function being parsed. - A global supervector of vectors of possibly thrown types within each nested try block, or in the case of vector 0, the function body. I'm using a vector of possibly thrown types instead of a vector of allowed types as I can't calculate allowed types until all catch(){} blocks are read. I guess I could try using a "tree" instead of a vector. Not sure if that should be a supervector of trees or a supertree of trees? When a function body is entered: - The exception specification is written to the above vector. - An empty vector is added to element 0 of the above supervector. Whenever a try{} clause is met, this supervector is incremented with an empty vector. When a catch(){} clause is met, the caught type is removed from the appropriate vector. When a throw statement is met, the thrown type is added to the last vector of the supervector if it doesn't already exist. When a function call is met, all types in its exception specification are added to the last vector of the supervector if they don't already exist. When the function body exits, the exception specifier is checked against the possibly thrown types and warnings are emitted if necessary. I'm not sure yet how to represent a function that has no exception specifier. I'm currently thinking of just using an associated boolean for "throws anything". I'm hoping that wrapping these in "if(warn_strict_exceptions) {}" won't slow the parser down significantly. It shouldn't. Templates: Whenever a function call is made I would have to look up its declaration to determine its specification. This becomes problematic for template types. I'm not sure how to deal with template expansion. I haven't yet checked out how this happens inside GCC. For the first version I'll probably just ignore templates where possible. Later I can add: - Checking for calls to function pointers. - Exception specification checking for function pointer assignment. - Checks on template instantiation. - White-listing of headers whose declarations you don't want to be checked. (so that you can use it and still use std::vector etc without getting overloaded with warnings). Not sure of an appropriate syntax. Does this sound like the right way to go about this?