[Bug c++/64786] New: Eliminate exceptions thrown/caught inside a function
olegendo at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sun Jan 25 14:01:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64786
Bug ID: 64786
Summary: Eliminate exceptions thrown/caught inside a function
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: olegendo at gcc dot gnu.org
If I'm not mistaken, in the following example:
int test (int a, int b, int* c)
{
enum err_a_t { ERR_A };
enum err_b_t { ERR_B };
try
{
if ((a + b) == 123)
throw ERR_A;
if ((a - b) == 5)
throw ERR_B;
for (int i = 0; i < b; ++i)
c[i] = 4;
return 0;
}
catch (err_a_t)
{
c[0] = 0;
return -1;
}
catch (err_b_t)
{
c[0] = 1;
return -1;
}
catch (...)
{
__builtin_abort ();
}
}
... the exceptions can be eliminated and converted into something like this
unless -fnon-call-exceptions is used (the mem accesses could throw).
int test (int a, int b, int* c)
{
if ((a + b) == 123)
{
c[0] = 0;
return -1;
}
if ((a - b) == 5)
{
c[0] = 0;
return -1;
}
for (int i = 0; i < b; ++i)
c[i] = 4;
return 0;
}
.. because all possible exceptions are known and are also known to be caught in
the function itself and there's nothing to stack-unwind.
More information about the Gcc-bugs
mailing list