Topic: Exception specification matching
Author: Nathan Sidwell <nathan@acm.org>
Date: 1999/03/04 Raw View
Hi,
I'm involved in improving egcs g++'s checking of exception specifiers. We're
having a problem with the literal wording of the standard.
para 15.3/3 talks about how a catch clause checks whether it should catch a
particular exception. It is allowed to ignore top-level cv qualifiers and first
level cv qualifiers of the form `cv1 T* cv2' when checking for a base class of
the thrown object.
para 15.4/7 talks about whether an exception specification lets a particular
object get thrown from a function. It doesn't mention cv qualifiers at all. It
gives three cases for a type-id in the exception specification,
`class X' - can throw all objects of class X and public unambiguous
descendants
`Y *' - can throw all objects that are (pointers to Y) or (pointers to public
unambiguous descendatnts). By implication Y must be a class.
otherwise - must have same type. cv-qualified variants are distinct types
(3.9.3/1)
This wording is stricter than how catch clauses match, and that seems wrong. It
appears that 15.4/7 has forgotton to mention that cv qualifiers can be ignored
in the same way. As it stands, it seems that,
struct X{};
struct Y: public X{};
void fn3()throw(X const *)
{
static Y y;
throw &y;
}
should call unexpected. It also seems to imply that an exception specifier with
a top-level cv qualifier can never match an exception from the function, as
top level cv qualifiers are stripped in constructing the thrown object (15.1/3)
I'm inclined to implement the more relaxed checking which is consistent with
how catch clauses work, but at variance with strict adherence to 15.4/7. As it
happens the dynamic behaviour of g++ is to do just this, but it also affects
whether an overriding virtual function's exception specifier is valid -- that's
what I'm trying to get right.
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
You can up the bandwidth, but you can't up the speed of light
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.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 ]