This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
g++: suggestion for warning dealing with exception handling
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: g++: suggestion for warning dealing with exception handling
- From: "E. Jay Berkenbilt" <ejb at ql dot org>
- Date: Sun, 8 Aug 1999 20:19:25 -0400
- Reply-To: ejb at ql dot org
This isn't really a bug report -- it's a suggestion for a warning that
would be useful and probably easy to implement. First:
% g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
This is part of a RedHat 6.0 GNU/Linux system.
Consider the following code fragment:
#include <iostream.h>
class Base
{
};
class Derived: public Base
{
};
int main(int, char*[])
{
try
{
throw Derived();
}
catch (Base)
{
cout << "caught base" << endl;
}
catch (Derived)
{
cout << "caught derived" << endl;
}
return 0;
}
This code is almost certainly erroneous. If you run it, it says
"caught base". The reason is that catch clauses are evaluated in
order of appearance, and an instance of "Derived" matches both Base
and Derived. It would be nice if gcc would warn when a catch clause
will never be reached because another catch clause that precedes it
encompasses it.
--
E. Jay Berkenbilt (ejb@ql.org) | http://www.ql.org/q/