This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/15745] exception specification incorrectly changes the type of the exception thrown
- From: "bangerth at dealii dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 1 Jun 2004 15:27:59 -0000
- Subject: [Bug c++/15745] exception specification incorrectly changes the type of the exception thrown
- References: <20040531075856.15745.wsf@fultondesigns.co.uk>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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