[Bug c++/15745] exception specification incorrectly changes the type of the exception thrown
bangerth at dealii dot org
gcc-bugzilla@gcc.gnu.org
Tue Jun 1 15:28:00 GMT 2004
------- Additional Comments From bangerth at dealii dot org 2004-06-01 15:27 -------
Confirmed. Here's a small testcase:
-------------------
typedef int IntArray[10];
IntArray i;
void test_array()
#ifdef TEST
throw (IntArray)
#endif
{ throw i; }
int main () {
try {
test_array();
} catch (IntArray) {}
}
------------------
We get
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ x.cc ; ./a.out
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ x.cc -DTEST ; ./a.out
terminate called after throwing an instance of 'int*'
Aborted
The point is that if we throw an exception that violates the exception
specification, then it is converted into an unspec exception and we
abort. However, since we can catch the exception that we throw in the
main function if there is no exception specification on the function
body, it seems as if the exception thrown is really of type IntArray
and shouldn't violate the exception specification. I agree that this
is confusing and looks like a bug in gcc associated with decaying
arrays to pointers, though I'd like to solicit a second opinion on
this.
We get the same results for all gcc versions from 2.95 to mainline.
W.
--
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Known to fail| |2.95.3 3.3.1 3.0.4 3.4.0
| |3.5.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15745
More information about the Gcc-bugs
mailing list