Topic: Exception-specifications in templates


Author: "Jim Barry" <jim.barry@bigfoot.com>
Date: 1998/06/24
Raw View
This is a reply to an article in the thread "problems with locale and
its facets". I am posting it as a new thread because the discussion
has moved on from the original topic.

Christopher Eltschka wrote in message
<35909A5B.9ED08A4A@physik.tu-muenchen.de>...
>
>Unfortunately, strict specification checking fails for templates,
>since there's no way to "propagate" exception specifications.
>For example, the following code:
>
>template<class T> T min(T const& t1, T const& t2) throw (what???)
>{
>  return t1<t2? t1 : t2;
>}

Good point. I don't know what the solution is, in fact I suspect that
there isn't one. Actually, I am not a fan of exception-specifications.
What I really want instead is for the compiler to figure it out and
tell me what exceptions I am potentially failing to catch. I guess
that this would involve generating a function-call graph (similar to
that of a source browser), walking up the tree from each leaf to
main() and noting what exceptions can be thrown or caught at each
node. You would end up with compiler errors/warnings listing functions
that can throw exceptions that will not be caught and, ideally, a list
of the offending paths through the call graph. This would make the
arduous business of writing exception-specifications redundant.

My limited understanding of the way C++ compilers work tells me that
this is not possible because of the separate compilation of
translation units. However, I am wondering if it is possible for the
compiler to generate the neccessary information, and do the checking
at link-time. Or am I hoping for too much?

- Jim

--
Jim Barry, Thermoteknix Systems Ltd., Cambridge, UK.
http://www.thermoteknix.co.uk Queen's Award for Export 1998
Antispam address courtesy of http://www.bigfoot.com
Or e-mail direct: jim at thermoteknix dot co dot uk
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]